Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: source/libvpx/third_party/nestegg/src/nestegg.c

Issue 232133009: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/third_party/nestegg/README.webm ('k') | source/libvpx/tools_common.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright © 2010 Mozilla Foundation 2 * Copyright © 2010 Mozilla Foundation
3 * 3 *
4 * This program is made available under an ISC-style license. See the 4 * This program is made available under an ISC-style license. See the
5 * accompanying file LICENSE for details. 5 * accompanying file LICENSE for details.
6 */ 6 */
7 #include <assert.h> 7 #include <assert.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <string.h> 9 #include <string.h>
10 10
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 else 687 else
688 *val = value.d; 688 *val = value.d;
689 return 1; 689 return 1;
690 } 690 }
691 691
692 static int 692 static int
693 ne_read_string(nestegg * ctx, char ** val, uint64_t length) 693 ne_read_string(nestegg * ctx, char ** val, uint64_t length)
694 { 694 {
695 char * str; 695 char * str;
696 int r; 696 int r;
697 const size_t alloc_size = (size_t)length + 1;
697 698
698 if (length == 0 || length > LIMIT_STRING) 699 if (length == 0 || length > LIMIT_STRING)
699 return -1; 700 return -1;
700 str = ne_pool_alloc(length + 1, ctx->alloc_pool); 701 str = ne_pool_alloc(alloc_size, ctx->alloc_pool);
701 r = ne_io_read(ctx->io, (unsigned char *) str, length); 702 r = ne_io_read(ctx->io, (unsigned char *) str, alloc_size - 1);
702 if (r != 1) 703 if (r != 1)
703 return r; 704 return r;
704 str[length] = '\0'; 705 str[alloc_size - 1] = '\0';
705 *val = str; 706 *val = str;
706 return 1; 707 return 1;
707 } 708 }
708 709
709 static int 710 static int
710 ne_read_binary(nestegg * ctx, struct ebml_binary * val, uint64_t length) 711 ne_read_binary(nestegg * ctx, struct ebml_binary * val, uint64_t length)
711 { 712 {
712 if (length == 0 || length > LIMIT_BINARY) 713 if (length == 0 || length > LIMIT_BINARY)
713 return -1; 714 return -1;
714 val->data = ne_pool_alloc(length, ctx->alloc_pool); 715 val->length = (size_t)length;
715 val->length = length; 716 val->data = ne_pool_alloc(val->length, ctx->alloc_pool);
716 return ne_io_read(ctx->io, val->data, length); 717 return ne_io_read(ctx->io, val->data, val->length);
717 } 718 }
718 719
719 static int 720 static int
720 ne_get_uint(struct ebml_type type, uint64_t * value) 721 ne_get_uint(struct ebml_type type, uint64_t * value)
721 { 722 {
722 if (!type.read) 723 if (!type.read)
723 return -1; 724 return -1;
724 725
725 assert(type.type == TYPE_UINT); 726 assert(type.type == TYPE_UINT);
726 727
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 } 1037 }
1037 } 1038 }
1038 1039
1039 if (element->type == TYPE_MASTER) { 1040 if (element->type == TYPE_MASTER) {
1040 if (element->flags & DESC_FLAG_MULTI) 1041 if (element->flags & DESC_FLAG_MULTI)
1041 ne_read_master(ctx, element); 1042 ne_read_master(ctx, element);
1042 else 1043 else
1043 ne_read_single_master(ctx, element); 1044 ne_read_single_master(ctx, element);
1044 continue; 1045 continue;
1045 } else { 1046 } else {
1046 r = ne_read_simple(ctx, element, size); 1047 r = ne_read_simple(ctx, element, (size_t)size);
1047 if (r < 0) 1048 if (r < 0)
1048 break; 1049 break;
1049 } 1050 }
1050 } else if (ne_is_ancestor_element(id, ctx->ancestor->previous)) { 1051 } else if (ne_is_ancestor_element(id, ctx->ancestor->previous)) {
1051 ctx->log(ctx, NESTEGG_LOG_DEBUG, "parent element %llx", id); 1052 ctx->log(ctx, NESTEGG_LOG_DEBUG, "parent element %llx", id);
1052 if (top_level && ctx->ancestor->node == top_level) { 1053 if (top_level && ctx->ancestor->node == top_level) {
1053 ctx->log(ctx, NESTEGG_LOG_DEBUG, "*** parse about to back up past top_le vel"); 1054 ctx->log(ctx, NESTEGG_LOG_DEBUG, "*** parse about to back up past top_le vel");
1054 r = 1; 1055 r = 1;
1055 break; 1056 break;
1056 } 1057 }
1057 ne_ctx_pop(ctx); 1058 ne_ctx_pop(ctx);
1058 } else { 1059 } else {
1059 r = ne_read_element(ctx, &id, &size); 1060 r = ne_read_element(ctx, &id, &size);
1060 if (r != 1) 1061 if (r != 1)
1061 break; 1062 break;
1062 1063
1063 if (id != ID_VOID && id != ID_CRC32) 1064 if (id != ID_VOID && id != ID_CRC32)
1064 ctx->log(ctx, NESTEGG_LOG_DEBUG, "unknown element %llx", id); 1065 ctx->log(ctx, NESTEGG_LOG_DEBUG, "unknown element %llx", id);
1065 r = ne_io_read_skip(ctx->io, size); 1066 r = ne_io_read_skip(ctx->io, (size_t)size);
1066 if (r != 1) 1067 if (r != 1)
1067 break; 1068 break;
1068 } 1069 }
1069 } 1070 }
1070 1071
1071 if (r != 1) 1072 if (r != 1)
1072 while (ctx->ancestor) 1073 while (ctx->ancestor)
1073 ne_ctx_pop(ctx); 1074 ne_ctx_pop(ctx);
1074 1075
1075 return r; 1076 return r;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 ne_read_ebml_lacing(nestegg_io * io, size_t block, size_t * read, uint64_t n, ui nt64_t * sizes) 1145 ne_read_ebml_lacing(nestegg_io * io, size_t block, size_t * read, uint64_t n, ui nt64_t * sizes)
1145 { 1146 {
1146 int r; 1147 int r;
1147 uint64_t lace, sum, length; 1148 uint64_t lace, sum, length;
1148 int64_t slace; 1149 int64_t slace;
1149 size_t i = 0; 1150 size_t i = 0;
1150 1151
1151 r = ne_read_vint(io, &lace, &length); 1152 r = ne_read_vint(io, &lace, &length);
1152 if (r != 1) 1153 if (r != 1)
1153 return r; 1154 return r;
1154 *read += length; 1155 assert(length <= 8);
1156 *read += (size_t)length;
1155 1157
1156 sizes[i] = lace; 1158 sizes[i] = lace;
1157 sum = sizes[i]; 1159 sum = sizes[i];
1158 1160
1159 i += 1; 1161 i += 1;
1160 n -= 1; 1162 n -= 1;
1161 1163
1162 while (--n) { 1164 while (--n) {
1163 r = ne_read_svint(io, &slace, &length); 1165 r = ne_read_svint(io, &slace, &length);
1164 if (r != 1) 1166 if (r != 1)
1165 return r; 1167 return r;
1166 *read += length; 1168 assert(length <= 8);
1169 *read += (size_t)length;
1167 sizes[i] = sizes[i - 1] + slace; 1170 sizes[i] = sizes[i - 1] + slace;
1168 sum += sizes[i]; 1171 sum += sizes[i];
1169 i += 1; 1172 i += 1;
1170 } 1173 }
1171 1174
1172 if (*read + sum > block) 1175 if (*read + sum > block)
1173 return -1; 1176 return -1;
1174 1177
1175 /* Last frame is the remainder of the block. */ 1178 /* Last frame is the remainder of the block. */
1176 sizes[i] = block - *read - sum; 1179 sizes[i] = block - *read - sum;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 if (block_size > LIMIT_BLOCK) 1259 if (block_size > LIMIT_BLOCK)
1257 return -1; 1260 return -1;
1258 1261
1259 r = ne_read_vint(ctx->io, &track_number, &length); 1262 r = ne_read_vint(ctx->io, &track_number, &length);
1260 if (r != 1) 1263 if (r != 1)
1261 return r; 1264 return r;
1262 1265
1263 if (track_number == 0 || (unsigned int)track_number != track_number) 1266 if (track_number == 0 || (unsigned int)track_number != track_number)
1264 return -1; 1267 return -1;
1265 1268
1266 consumed += length; 1269 assert(length <= 8);
1270 consumed += (size_t)length;
1267 1271
1268 r = ne_read_int(ctx->io, &timecode, 2); 1272 r = ne_read_int(ctx->io, &timecode, 2);
1269 if (r != 1) 1273 if (r != 1)
1270 return r; 1274 return r;
1271 1275
1272 consumed += 2; 1276 consumed += 2;
1273 1277
1274 r = ne_read_uint(ctx->io, &flags, 1); 1278 r = ne_read_uint(ctx->io, &flags, 1);
1275 if (r != 1) 1279 if (r != 1)
1276 return r; 1280 return r;
(...skipping 23 matching lines...) Expand all
1300 if (frames > 256) 1304 if (frames > 256)
1301 return -1; 1305 return -1;
1302 1306
1303 switch (lacing) { 1307 switch (lacing) {
1304 case LACING_NONE: 1308 case LACING_NONE:
1305 frame_sizes[0] = block_size - consumed; 1309 frame_sizes[0] = block_size - consumed;
1306 break; 1310 break;
1307 case LACING_XIPH: 1311 case LACING_XIPH:
1308 if (frames == 1) 1312 if (frames == 1)
1309 return -1; 1313 return -1;
1310 r = ne_read_xiph_lacing(ctx->io, block_size, &consumed, frames, frame_sizes) ; 1314 r = ne_read_xiph_lacing(ctx->io, (size_t)block_size, &consumed, frames, fram e_sizes);
1311 if (r != 1) 1315 if (r != 1)
1312 return r; 1316 return r;
1313 break; 1317 break;
1314 case LACING_FIXED: 1318 case LACING_FIXED:
1315 if ((block_size - consumed) % frames) 1319 if ((block_size - consumed) % frames)
1316 return -1; 1320 return -1;
1317 for (i = 0; i < frames; ++i) 1321 for (i = 0; i < frames; ++i)
1318 frame_sizes[i] = (block_size - consumed) / frames; 1322 frame_sizes[i] = (block_size - consumed) / frames;
1319 break; 1323 break;
1320 case LACING_EBML: 1324 case LACING_EBML:
1321 if (frames == 1) 1325 if (frames == 1)
1322 return -1; 1326 return -1;
1323 r = ne_read_ebml_lacing(ctx->io, block_size, &consumed, frames, frame_sizes) ; 1327 r = ne_read_ebml_lacing(ctx->io, (size_t)block_size, &consumed, frames, fram e_sizes);
1324 if (r != 1) 1328 if (r != 1)
1325 return r; 1329 return r;
1326 break; 1330 break;
1327 } 1331 }
1328 1332
1329 /* Sanity check unlaced frame sizes against total block size. */ 1333 /* Sanity check unlaced frame sizes against total block size. */
1330 total = consumed; 1334 total = consumed;
1331 for (i = 0; i < frames; ++i) 1335 for (i = 0; i < frames; ++i)
1332 total += frame_sizes[i]; 1336 total += frame_sizes[i];
1333 if (total > block_size) 1337 if (total > block_size)
(...skipping 24 matching lines...) Expand all
1358 ctx->log(ctx, NESTEGG_LOG_DEBUG, "%sblock t %lld pts %f f %llx frames: %llu", 1362 ctx->log(ctx, NESTEGG_LOG_DEBUG, "%sblock t %lld pts %f f %llx frames: %llu",
1359 block_id == ID_BLOCK ? "" : "simple", pkt->track, pkt->timecode / 1e9 , flags, frames); 1363 block_id == ID_BLOCK ? "" : "simple", pkt->track, pkt->timecode / 1e9 , flags, frames);
1360 1364
1361 last = NULL; 1365 last = NULL;
1362 for (i = 0; i < frames; ++i) { 1366 for (i = 0; i < frames; ++i) {
1363 if (frame_sizes[i] > LIMIT_FRAME) { 1367 if (frame_sizes[i] > LIMIT_FRAME) {
1364 nestegg_free_packet(pkt); 1368 nestegg_free_packet(pkt);
1365 return -1; 1369 return -1;
1366 } 1370 }
1367 f = ne_alloc(sizeof(*f)); 1371 f = ne_alloc(sizeof(*f));
1368 f->data = ne_alloc(frame_sizes[i]); 1372 f->length = (size_t)frame_sizes[i];
1369 f->length = frame_sizes[i]; 1373 f->data = ne_alloc(f->length);
1370 r = ne_io_read(ctx->io, f->data, frame_sizes[i]); 1374 r = ne_io_read(ctx->io, f->data, f->length);
1371 if (r != 1) { 1375 if (r != 1) {
1372 free(f->data); 1376 free(f->data);
1373 free(f); 1377 free(f);
1374 nestegg_free_packet(pkt); 1378 nestegg_free_packet(pkt);
1375 return -1; 1379 return -1;
1376 } 1380 }
1377 1381
1378 if (!last) 1382 if (!last)
1379 pkt->frame = f; 1383 pkt->frame = f;
1380 else 1384 else
(...skipping 18 matching lines...) Expand all
1399 if (r != 1) 1403 if (r != 1)
1400 return r; 1404 return r;
1401 1405
1402 if (id != ID_DISCARD_PADDING) 1406 if (id != ID_DISCARD_PADDING)
1403 return 1; 1407 return 1;
1404 1408
1405 element = ne_find_element(id, ctx->ancestor->node); 1409 element = ne_find_element(id, ctx->ancestor->node);
1406 if (!element) 1410 if (!element)
1407 return 1; 1411 return 1;
1408 1412
1409 r = ne_read_simple(ctx, element, size); 1413 assert((size_t)size == size);
1414 r = ne_read_simple(ctx, element, (size_t)size);
1410 if (r != 1) 1415 if (r != 1)
1411 return r; 1416 return r;
1412 storage = (struct ebml_type *) (ctx->ancestor->data + element->offset); 1417 storage = (struct ebml_type *) (ctx->ancestor->data + element->offset);
1413 pkt->discard_padding = storage->v.i; 1418 pkt->discard_padding = storage->v.i;
1414 1419
1415 return 1; 1420 return 1;
1416 } 1421 }
1417 1422
1418 1423
1419 static uint64_t 1424 static uint64_t
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1593 size_t length; 1598 size_t length;
1594 int64_t offset; 1599 int64_t offset;
1595 }; 1600 };
1596 1601
1597 static int 1602 static int
1598 ne_buffer_read(void * buffer, size_t length, void * user_data) 1603 ne_buffer_read(void * buffer, size_t length, void * user_data)
1599 { 1604 {
1600 struct sniff_buffer * sb = user_data; 1605 struct sniff_buffer * sb = user_data;
1601 1606
1602 int rv = 1; 1607 int rv = 1;
1603 size_t available = sb->length - sb->offset; 1608 size_t available = sb->length - (size_t)sb->offset;
1604 1609
1605 if (available < length) 1610 if (available < length)
1606 return 0; 1611 return 0;
1607 1612
1608 memcpy(buffer, sb->buffer + sb->offset, length); 1613 memcpy(buffer, sb->buffer + sb->offset, length);
1609 sb->offset += length; 1614 sb->offset += length;
1610 1615
1611 return rv; 1616 return rv;
1612 } 1617 }
1613 1618
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
2067 i += 1; 2072 i += 1;
2068 } 2073 }
2069 sizes[i] = codec_private.length - total - (p - codec_private.data); 2074 sizes[i] = codec_private.length - total - (p - codec_private.data);
2070 2075
2071 for (i = 0; i < item; ++i) { 2076 for (i = 0; i < item; ++i) {
2072 if (sizes[i] > LIMIT_FRAME) 2077 if (sizes[i] > LIMIT_FRAME)
2073 return -1; 2078 return -1;
2074 p += sizes[i]; 2079 p += sizes[i];
2075 } 2080 }
2076 *data = p; 2081 *data = p;
2077 *length = sizes[item]; 2082 *length = (size_t)sizes[item];
2078 } else { 2083 } else {
2079 *data = codec_private.data; 2084 *data = codec_private.data;
2080 *length = codec_private.length; 2085 *length = codec_private.length;
2081 } 2086 }
2082 2087
2083 return 0; 2088 return 0;
2084 } 2089 }
2085 2090
2086 int 2091 int
2087 nestegg_track_video_params(nestegg * ctx, unsigned int track, 2092 nestegg_track_video_params(nestegg * ctx, unsigned int track,
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
2309 user_data.length = length; 2314 user_data.length = length;
2310 user_data.offset = 0; 2315 user_data.offset = 0;
2311 2316
2312 io.read = ne_buffer_read; 2317 io.read = ne_buffer_read;
2313 io.seek = ne_buffer_seek; 2318 io.seek = ne_buffer_seek;
2314 io.tell = ne_buffer_tell; 2319 io.tell = ne_buffer_tell;
2315 io.userdata = &user_data; 2320 io.userdata = &user_data;
2316 return ne_match_webm(io, length); 2321 return ne_match_webm(io, length);
2317 } 2322 }
2318 2323
OLDNEW
« no previous file with comments | « source/libvpx/third_party/nestegg/README.webm ('k') | source/libvpx/tools_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698