get_packetheader() forgot to read the header_checksum in big packets

patch from Clemens Ladisch cladisch AT fastmail dot net
(stray base64 patch reverted in the next commits)

Originally committed as revision 8156 to svn://svn.ffmpeg.org/ffmpeg/trunk
pull/126/head
Luca Barbato 18 years ago
parent c2a29455e3
commit bb0eb714bd
  1. 7
      libavformat/http.c
  2. 2
      libavformat/nutdec.c
  3. 2
      libavutil/Makefile
  4. 4
      libavutil/avutil.h
  5. 27
      libavutil/base64.c
  6. 6
      libavutil/base64.h

@ -206,14 +206,17 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr,
HTTPContext *s = h->priv_data; HTTPContext *s = h->priv_data;
int post, err, ch; int post, err, ch;
char line[1024], *q; char line[1024], *q;
char *auth_b64; char *auth_b64 = av_malloc(strlen(auth) * 4 / 3 + 12);
offset_t off = s->off; offset_t off = s->off;
if (auth_b64 == NULL) return AVERROR(ENOMEM);
/* send http header */ /* send http header */
post = h->flags & URL_WRONLY; post = h->flags & URL_WRONLY;
auth_b64 = av_base64_encode((uint8_t *)auth, strlen(auth)); auth_b64 = av_base64_encode(auth_b64, strlen(auth) * 4 / 3 + 12,
(uint8_t *)auth, strlen(auth));
snprintf(s->buffer, sizeof(s->buffer), snprintf(s->buffer, sizeof(s->buffer),
"%s %s HTTP/1.1\r\n" "%s %s HTTP/1.1\r\n"
"User-Agent: %s\r\n" "User-Agent: %s\r\n"

@ -104,6 +104,8 @@ static int get_packetheader(NUTContext *nut, ByteIOContext *bc, int calculate_ch
// start= url_ftell(bc) - 8; // start= url_ftell(bc) - 8;
size= get_v(bc); size= get_v(bc);
if(size > 4096)
get_be32(bc); //FIXME check this
init_checksum(bc, calculate_checksum ? av_crc04C11DB7_update : NULL, 0); init_checksum(bc, calculate_checksum ? av_crc04C11DB7_update : NULL, 0);

@ -18,7 +18,7 @@ OBJS= mathematics.o \
HEADERS = avutil.h common.h mathematics.h integer.h rational.h \ HEADERS = avutil.h common.h mathematics.h integer.h rational.h \
intfloat_readwrite.h md5.h adler32.h log.h fifo.h lzo.h \ intfloat_readwrite.h md5.h adler32.h log.h fifo.h lzo.h \
random.h random.h base64.h
NAME=avutil NAME=avutil
LIBVERSION=$(LAVUVERSION) LIBVERSION=$(LAVUVERSION)

@ -34,8 +34,8 @@ extern "C" {
#define AV_STRINGIFY(s) AV_TOSTRING(s) #define AV_STRINGIFY(s) AV_TOSTRING(s)
#define AV_TOSTRING(s) #s #define AV_TOSTRING(s) #s
#define LIBAVUTIL_VERSION_INT ((49<<16)+(3<<8)+0) #define LIBAVUTIL_VERSION_INT ((49<<16)+(4<<8)+0)
#define LIBAVUTIL_VERSION 49.3.0 #define LIBAVUTIL_VERSION 49.4.0
#define LIBAVUTIL_BUILD LIBAVUTIL_VERSION_INT #define LIBAVUTIL_BUILD LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_IDENT "Lavu" AV_STRINGIFY(LIBAVUTIL_VERSION) #define LIBAVUTIL_IDENT "Lavu" AV_STRINGIFY(LIBAVUTIL_VERSION)

@ -70,17 +70,17 @@ int av_base64_decode(uint8_t * out, const char *in, int out_length)
* fixed edge cases and made it work from data (vs. strings) by ryan. * fixed edge cases and made it work from data (vs. strings) by ryan.
*****************************************************************************/ *****************************************************************************/
char *av_base64_encode(uint8_t * src, int len) char *av_base64_encode(char *out, int out_len, uint8_t * src, int len)
{ {
static const char b64[] = static const char b64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
char *ret, *dst; char *dst;
unsigned i_bits = 0; unsigned i_bits = 0;
int i_shift = 0; int i_shift = 0;
int bytes_remaining = len; int bytes_remaining = len;
if (len < UINT_MAX / 4) { if (len < UINT_MAX / 4 && out_len > (len * 4 / 3 + 12) && out) {
ret = dst = av_malloc(len * 4 / 3 + 12); dst = out;
} else } else
return NULL; return NULL;
@ -95,12 +95,12 @@ char *av_base64_encode(uint8_t * src, int len)
i_shift -= 6; i_shift -= 6;
} while (i_shift > 6 || (bytes_remaining == 0 && i_shift > 0)); } while (i_shift > 6 || (bytes_remaining == 0 && i_shift > 0));
} }
while ((dst - ret) & 3) while ((dst - out) & 3)
*dst++ = '='; *dst++ = '=';
} }
*dst = '\0'; *dst = '\0';
return ret; return out;
} }
// #define TEST_BASE64 // #define TEST_BASE64
@ -131,10 +131,12 @@ int b64test()
}; };
for (t = tests; t->data; t++) { for (t = tests; t->data; t++) {
char *str; char *str;
int ret;
av_log(NULL, AV_LOG_ERROR, "Encoding %s...\n", (char *) t->data); av_log(NULL, AV_LOG_ERROR, "Encoding %s...\n", (char *) t->data);
str = av_base64_encode(t->data, t->len); str = av_malloc(t->len * 4 / 3 + 12);
if (str) { ret = av_base64_encode(str, t->len * 4 / 3 + 12, t->data, t->len);
if (ret > 0) {
av_log(NULL, AV_LOG_ERROR, "Encoded to %s...\n", str); av_log(NULL, AV_LOG_ERROR, "Encoded to %s...\n", str);
if (strcmp(str, t->result) != 0) { if (strcmp(str, t->result) != 0) {
av_log(NULL, AV_LOG_ERROR, "failed test %d: %s != %s\n", av_log(NULL, AV_LOG_ERROR, "failed test %d: %s != %s\n",
@ -168,9 +170,9 @@ int b64test()
srand(123141); // time(NULL)); srand(123141); // time(NULL));
for (test_count = 0; test_count < 100; test_count++) { for (test_count = 0; test_count < 100; test_count++) {
int size = rand() % 1024; int size = rand() % 1024;
int ii; int ii, ret;
uint8_t *data; uint8_t *data;
char *encoded_result; char *encoded_result = av_malloc(size * 4 / 3 + 12);
av_log(NULL, AV_LOG_ERROR, "Test %d: Size %d bytes...", av_log(NULL, AV_LOG_ERROR, "Test %d: Size %d bytes...",
test_count, size); test_count, size);
@ -179,8 +181,9 @@ int b64test()
data[ii] = rand() % 255; data[ii] = rand() % 255;
} }
encoded_result = av_base64_encode(data, size); ret = av_base64_encode(encoded_result, size * 4 / 3 + 12,
if (encoded_result) { data, size);
if (ret > 0) {
int decode_buffer_size = size + 10; // try without 10 as well int decode_buffer_size = size + 10; // try without 10 as well
uint8_t *decode_buffer = av_malloc(decode_buffer_size); uint8_t *decode_buffer = av_malloc(decode_buffer_size);
if (decode_buffer) { if (decode_buffer) {

@ -27,7 +27,11 @@ int av_base64_decode(uint8_t * out, const char *in, int out_length);
/** /**
* encodes base64 * encodes base64
* @param out string
* @param out_len of the string, must be at least (len * 4 / 3 + 12)
* @param src data, not a string * @param src data, not a string
* @param len data length
* @return the zero terminated encoded string or NULL in case of errors
*/ */
char *av_base64_encode(uint8_t * src, int len); char *av_base64_encode(char *out, int out_len, uint8_t * src, int len);

Loading…
Cancel
Save