Otherwise it might happen that invalid dimensions are used when reading a video packet; this might lead to undefined overflow.
Unified · Split
| @@ -132,23 +132,25 @@ static int scan_file(AVFormatContext *avctx, AVStream *vst, AVStream *ast, int f · 131 unmodified lines | |||
| 132 | break; | 132 | break; |
| 133 | size -= 16; | 133 | size -= 16; |
| 134 | if (vst && type == MKTAG('R','A','W','I') && size >= 164) { | 134 | if (vst && type == MKTAG('R','A','W','I') && size >= 164) { |
| 135 | vst->codecpar->width = avio_rl16(pb); | 135 | unsigned width = avio_rl16(pb); |
| 136 | vst->codecpar->height = avio_rl16(pb); | 136 | unsigned height = avio_rl16(pb); |
| 137 | ret = av_image_check_size(vst->codecpar->width, vst->codecpar->height, 0, avctx); | 137 | unsigned bits_per_coded_sample; |
| 138 | ret = av_image_check_size(width, height, 0, avctx); | ||
| 138 | if (ret < 0) | 139 | if (ret < 0) |
| 139 | return ret; | 140 | return ret; |
| 140 | if (avio_rl32(pb) != 1) | 141 | if (avio_rl32(pb) != 1) |
| 141 | avpriv_request_sample(avctx, "raw api version"); | 142 | avpriv_request_sample(avctx, "raw api version"); |
| 142 | avio_skip(pb, 20); // pointer, width, height, pitch, frame_size | 143 | avio_skip(pb, 20); // pointer, width, height, pitch, frame_size |
| 143 | vst->codecpar->bits_per_coded_sample = avio_rl32(pb); | 144 | bits_per_coded_sample = avio_rl32(pb); |
| 144 | if (vst->codecpar->bits_per_coded_sample < 0 || | 145 | if (bits_per_coded_sample > (INT_MAX - 7) / (width * height)) { |
| 145 | vst->codecpar->bits_per_coded_sample > (INT_MAX - 7) / (vst->codecpar->width * vst->codecpar->height)) { | ||
| 146 | av_log(avctx, AV_LOG_ERROR, | 146 | av_log(avctx, AV_LOG_ERROR, |
| 147 | "invalid bits_per_coded_sample %d (size: %dx%d)\n", | 147 | "invalid bits_per_coded_sample %u (size: %ux%u)\n", |
| 148 | vst->codecpar->bits_per_coded_sample, | 148 | bits_per_coded_sample, width, height); |
| 149 | vst->codecpar->width, vst->codecpar->height); | ||
| 150 | return AVERROR_INVALIDDATA; | 149 | return AVERROR_INVALIDDATA; |
| 151 | } | 150 | } |
| 151 | vst->codecpar->width = width; | ||
| 152 | vst->codecpar->height = height; | ||
| 153 | vst->codecpar->bits_per_coded_sample = bits_per_coded_sample; | ||
| 152 | avio_skip(pb, 8 + 16 + 24); // black_level, white_level, xywh, active_area, exposure_bias | 154 | avio_skip(pb, 8 + 16 + 24); // black_level, white_level, xywh, active_area, exposure_bias |
| 153 | if (avio_rl32(pb) != 0x2010100) /* RGGB */ | 155 | if (avio_rl32(pb) != 0x2010100) /* RGGB */ |
| 154 | avpriv_request_sample(avctx, "cfa_pattern"); | 156 | avpriv_request_sample(avctx, "cfa_pattern"); |