(cherry picked from commit 845bb401781ef04e342bd558df16a8dbf5f800f9)
Ronald S. Bultje authored on 2016/12/06 00:18:10... | ... |
@@ -1153,6 +1153,34 @@ static int http_buf_read(URLContext *h, uint8_t *buf, int size) |
1153 | 1153 |
{ |
1154 | 1154 |
HTTPContext *s = h->priv_data; |
1155 | 1155 |
int len; |
1156 |
+ |
|
1157 |
+ if (s->chunksize != UINT64_MAX) { |
|
1158 |
+ if (!s->chunksize) { |
|
1159 |
+ char line[32]; |
|
1160 |
+ int err; |
|
1161 |
+ |
|
1162 |
+ do { |
|
1163 |
+ if ((err = http_get_line(s, line, sizeof(line))) < 0) |
|
1164 |
+ return err; |
|
1165 |
+ } while (!*line); /* skip CR LF from last chunk */ |
|
1166 |
+ |
|
1167 |
+ s->chunksize = strtoull(line, NULL, 16); |
|
1168 |
+ |
|
1169 |
+ av_log(h, AV_LOG_TRACE, |
|
1170 |
+ "Chunked encoding data size: %"PRIu64"'\n", |
|
1171 |
+ s->chunksize); |
|
1172 |
+ |
|
1173 |
+ if (!s->chunksize) |
|
1174 |
+ return 0; |
|
1175 |
+ else if (s->chunksize == UINT64_MAX) { |
|
1176 |
+ av_log(h, AV_LOG_ERROR, "Invalid chunk size %"PRIu64"\n", |
|
1177 |
+ s->chunksize); |
|
1178 |
+ return AVERROR(EINVAL); |
|
1179 |
+ } |
|
1180 |
+ } |
|
1181 |
+ size = FFMIN(size, s->chunksize); |
|
1182 |
+ } |
|
1183 |
+ |
|
1156 | 1184 |
/* read bytes from input buffer first */ |
1157 | 1185 |
len = s->buf_end - s->buf_ptr; |
1158 | 1186 |
if (len > 0) { |
... | ... |
@@ -1175,8 +1203,10 @@ static int http_buf_read(URLContext *h, uint8_t *buf, int size) |
1175 | 1175 |
} |
1176 | 1176 |
if (len > 0) { |
1177 | 1177 |
s->off += len; |
1178 |
- if (s->chunksize > 0) |
|
1178 |
+ if (s->chunksize > 0) { |
|
1179 |
+ av_assert0(s->chunksize >= len); |
|
1179 | 1180 |
s->chunksize -= len; |
1181 |
+ } |
|
1180 | 1182 |
} |
1181 | 1183 |
return len; |
1182 | 1184 |
} |
... | ... |
@@ -1231,31 +1261,6 @@ static int http_read_stream(URLContext *h, uint8_t *buf, int size) |
1231 | 1231 |
return err; |
1232 | 1232 |
} |
1233 | 1233 |
|
1234 |
- if (s->chunksize != UINT64_MAX) { |
|
1235 |
- if (!s->chunksize) { |
|
1236 |
- char line[32]; |
|
1237 |
- |
|
1238 |
- do { |
|
1239 |
- if ((err = http_get_line(s, line, sizeof(line))) < 0) |
|
1240 |
- return err; |
|
1241 |
- } while (!*line); /* skip CR LF from last chunk */ |
|
1242 |
- |
|
1243 |
- s->chunksize = strtoull(line, NULL, 16); |
|
1244 |
- |
|
1245 |
- av_log(h, AV_LOG_TRACE, |
|
1246 |
- "Chunked encoding data size: %"PRIu64"'\n", |
|
1247 |
- s->chunksize); |
|
1248 |
- |
|
1249 |
- if (!s->chunksize) |
|
1250 |
- return 0; |
|
1251 |
- else if (s->chunksize == UINT64_MAX) { |
|
1252 |
- av_log(h, AV_LOG_ERROR, "Invalid chunk size %"PRIu64"\n", |
|
1253 |
- s->chunksize); |
|
1254 |
- return AVERROR(EINVAL); |
|
1255 |
- } |
|
1256 |
- } |
|
1257 |
- size = FFMIN(size, s->chunksize); |
|
1258 |
- } |
|
1259 | 1234 |
#if CONFIG_ZLIB |
1260 | 1235 |
if (s->compressed) |
1261 | 1236 |
return http_buf_read_compressed(h, buf, size); |