comparison matroskadec.c @ 3414:703f452f00f1 libavformat

reorganize matroska_add_stream() to fix potential mem leak and buffer overflow fix CID44
author aurel
date Mon, 02 Jun 2008 23:07:41 +0000
parents b7f86452706e
children 89f651b6f12a
comparison
equal deleted inserted replaced
3413:b7f86452706e 3414:703f452f00f1
1019 { 1019 {
1020 int res = 0; 1020 int res = 0;
1021 uint32_t id; 1021 uint32_t id;
1022 MatroskaTrack *track; 1022 MatroskaTrack *track;
1023 1023
1024 av_log(matroska->ctx, AV_LOG_DEBUG, "parsing track, adding stream..,\n");
1025
1026 /* Allocate a generic track. As soon as we know its type we'll realloc. */
1027 track = av_mallocz(MAX_TRACK_SIZE);
1028 matroska->num_tracks++;
1029 strcpy(track->language, "eng");
1030
1031 /* start with the master */ 1024 /* start with the master */
1032 if ((res = ebml_read_master(matroska, &id)) < 0) 1025 if ((res = ebml_read_master(matroska, &id)) < 0)
1033 return res; 1026 return res;
1027
1028 av_log(matroska->ctx, AV_LOG_DEBUG, "parsing track, adding stream..,\n");
1029
1030 /* Allocate a generic track. As soon as we know its type we'll realloc. */
1031 track = av_mallocz(MAX_TRACK_SIZE);
1032 strcpy(track->language, "eng");
1034 1033
1035 /* try reading the trackentry headers */ 1034 /* try reading the trackentry headers */
1036 while (res == 0) { 1035 while (res == 0) {
1037 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { 1036 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
1038 res = AVERROR(EIO); 1037 res = AVERROR(EIO);
1086 "Unknown or unsupported track type 0x%x\n", 1085 "Unknown or unsupported track type 0x%x\n",
1087 track->type); 1086 track->type);
1088 track->type = MATROSKA_TRACK_TYPE_NONE; 1087 track->type = MATROSKA_TRACK_TYPE_NONE;
1089 break; 1088 break;
1090 } 1089 }
1091 matroska->tracks[matroska->num_tracks - 1] = track;
1092 break; 1090 break;
1093 } 1091 }
1094 1092
1095 /* tracktype specific stuff for video */ 1093 /* tracktype specific stuff for video */
1096 case MATROSKA_ID_TRACKVIDEO: { 1094 case MATROSKA_ID_TRACKVIDEO: {
1621 matroska->level_up--; 1619 matroska->level_up--;
1622 break; 1620 break;
1623 } 1621 }
1624 } 1622 }
1625 1623
1624 if (track->type && matroska->num_tracks < ARRAY_SIZE(matroska->tracks)) {
1625 matroska->tracks[matroska->num_tracks++] = track;
1626 } else {
1627 av_free(track);
1628 }
1626 return res; 1629 return res;
1627 } 1630 }
1628 1631
1629 static int 1632 static int
1630 matroska_parse_tracks (MatroskaDemuxContext *matroska) 1633 matroska_parse_tracks (MatroskaDemuxContext *matroska)