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

Side by Side Diff: source/patched-ffmpeg/libavcodec/h264.c

Issue 9340008: Avoid OOB reads in nal parsing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/ffmpeg/
Patch Set: Created 8 years, 10 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 | « patches/to_upstream/55_h264_nal.patch ('k') | no next file » | 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 * H.26L/H.264/AVC/JVT/14496-10/... decoder 2 * H.26L/H.264/AVC/JVT/14496-10/... decoder
3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> 3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
4 * 4 *
5 * This file is part of FFmpeg. 5 * This file is part of FFmpeg.
6 * 6 *
7 * FFmpeg is free software; you can redistribute it and/or 7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public 8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version. 10 * version 2.1 of the License, or (at your option) any later version.
(...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 981
982 memset(h->pps.scaling_matrix4, 16, 6*16*sizeof(uint8_t)); 982 memset(h->pps.scaling_matrix4, 16, 6*16*sizeof(uint8_t));
983 memset(h->pps.scaling_matrix8, 16, 2*64*sizeof(uint8_t)); 983 memset(h->pps.scaling_matrix8, 16, 2*64*sizeof(uint8_t));
984 } 984 }
985 985
986 int ff_h264_decode_extradata(H264Context *h) 986 int ff_h264_decode_extradata(H264Context *h)
987 { 987 {
988 AVCodecContext *avctx = h->s.avctx; 988 AVCodecContext *avctx = h->s.avctx;
989 989
990 if(avctx->extradata[0] == 1){ 990 if(avctx->extradata[0] == 1){
991 int i, cnt, nalsize; 991 int i, cnt, nalsize, size_left;
992 unsigned char *p = avctx->extradata; 992 unsigned char *p = avctx->extradata;
993 size_left = avctx->extradata_size;
993 994
994 h->is_avc = 1; 995 h->is_avc = 1;
995 996
996 if(avctx->extradata_size < 7) { 997 if(size_left < 7) {
997 av_log(avctx, AV_LOG_ERROR, "avcC too short\n"); 998 av_log(avctx, AV_LOG_ERROR, "avcC too short\n");
998 return -1; 999 return -1;
999 } 1000 }
1000 /* sps and pps in the avcC always have length coded with 2 bytes, 1001 /* sps and pps in the avcC always have length coded with 2 bytes,
1001 so put a fake nal_length_size = 2 while parsing them */ 1002 so put a fake nal_length_size = 2 while parsing them */
1002 h->nal_length_size = 2; 1003 h->nal_length_size = 2;
1003 // Decode sps from avcC 1004 // Decode sps from avcC
1004 cnt = *(p+5) & 0x1f; // Number of sps 1005 cnt = *(p+5) & 0x1f; // Number of sps
1005 p += 6; 1006 p += 6;
1007 size_left -= 6;
1006 for (i = 0; i < cnt; i++) { 1008 for (i = 0; i < cnt; i++) {
1009 if (size_left < 2) {
1010 av_log(avctx, AV_LOG_ERROR, "Cannot read sps nalsize\n");
1011 return -1;
1012 }
1007 nalsize = AV_RB16(p) + 2; 1013 nalsize = AV_RB16(p) + 2;
1014 if (size_left < nalsize) {
1015 av_log(avctx, AV_LOG_ERROR, "sps nalsize too big\n");
1016 return -1;
1017 }
1008 if(decode_nal_units(h, p, nalsize) < 0) { 1018 if(decode_nal_units(h, p, nalsize) < 0) {
1009 av_log(avctx, AV_LOG_ERROR, "Decoding sps %d from avcC failed\n" , i); 1019 av_log(avctx, AV_LOG_ERROR, "Decoding sps %d from avcC failed\n" , i);
1010 return -1; 1020 return -1;
1011 } 1021 }
1012 p += nalsize; 1022 p += nalsize;
1023 size_left -= nalsize;
1013 } 1024 }
1014 // Decode pps from avcC 1025 // Decode pps from avcC
1026 if(!size_left) {
1027 av_log(avctx, AV_LOG_ERROR, "Cannot read pps count\n");
1028 return -1;
1029 }
1015 cnt = *(p++); // Number of pps 1030 cnt = *(p++); // Number of pps
1031 --size_left;
1016 for (i = 0; i < cnt; i++) { 1032 for (i = 0; i < cnt; i++) {
1033 if (size_left < 2) {
1034 av_log(avctx, AV_LOG_ERROR, "Cannot read pps nalsize\n");
1035 return -1;
1036 }
1017 nalsize = AV_RB16(p) + 2; 1037 nalsize = AV_RB16(p) + 2;
1038 if (size_left < nalsize) {
1039 av_log(avctx, AV_LOG_ERROR, "pps nalsize too big\n");
1040 return -1;
1041 }
1018 if (decode_nal_units(h, p, nalsize) < 0) { 1042 if (decode_nal_units(h, p, nalsize) < 0) {
1019 av_log(avctx, AV_LOG_ERROR, "Decoding pps %d from avcC failed\n" , i); 1043 av_log(avctx, AV_LOG_ERROR, "Decoding pps %d from avcC failed\n" , i);
1020 return -1; 1044 return -1;
1021 } 1045 }
1022 p += nalsize; 1046 p += nalsize;
1047 size_left -= nalsize;
1023 } 1048 }
1024 // Now store right nal length size, that will be use to parse all other nals 1049 // Now store right nal length size, that will be use to parse all other nals
1025 h->nal_length_size = (avctx->extradata[4] & 0x03) + 1; 1050 h->nal_length_size = (avctx->extradata[4] & 0x03) + 1;
1026 } else { 1051 } else {
1027 h->is_avc = 0; 1052 h->is_avc = 0;
1028 if(decode_nal_units(h, avctx->extradata, avctx->extradata_size) < 0) 1053 if(decode_nal_units(h, avctx->extradata, avctx->extradata_size) < 0)
1029 return -1; 1054 return -1;
1030 } 1055 }
1031 return 0; 1056 return 0;
1032 } 1057 }
(...skipping 3126 matching lines...) Expand 10 before | Expand all | Expand 10 after
4159 NULL, 4184 NULL,
4160 ff_h264_decode_end, 4185 ff_h264_decode_end,
4161 decode_frame, 4186 decode_frame,
4162 CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU, 4187 CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU,
4163 .flush= flush_dpb, 4188 .flush= flush_dpb,
4164 .long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (VDPAU acceleration)"), 4189 .long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (VDPAU acceleration)"),
4165 .pix_fmts = (const enum PixelFormat[]){PIX_FMT_VDPAU_H264, PIX_FMT_NONE}, 4190 .pix_fmts = (const enum PixelFormat[]){PIX_FMT_VDPAU_H264, PIX_FMT_NONE},
4166 .profiles = NULL_IF_CONFIG_SMALL(profiles), 4191 .profiles = NULL_IF_CONFIG_SMALL(profiles),
4167 }; 4192 };
4168 #endif 4193 #endif
OLDNEW
« no previous file with comments | « patches/to_upstream/55_h264_nal.patch ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698