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 | 132 | break; |
| 133 | 133 | size -= 16; |
| 134 | 134 | if (vst && type == MKTAG('R','A','W','I') && size >= 164) { |
| 135 | − vst->codecpar->width = avio_rl16(pb); | |
| 136 | − vst->codecpar->height = avio_rl16(pb); | |
| 137 | − ret = av_image_check_size(vst->codecpar->width, vst->codecpar->height, 0, avctx); | |
| 135 | + unsigned width = avio_rl16(pb); | |
| 136 | + unsigned height = avio_rl16(pb); | |
| 137 | + unsigned bits_per_coded_sample; | |
| 138 | + ret = av_image_check_size(width, height, 0, avctx); | |
| 138 | 139 | if (ret < 0) |
| 139 | 140 | return ret; |
| 140 | 141 | if (avio_rl32(pb) != 1) |
| 141 | 142 | avpriv_request_sample(avctx, "raw api version"); |
| 142 | 143 | avio_skip(pb, 20); // pointer, width, height, pitch, frame_size |
| 143 | − vst->codecpar->bits_per_coded_sample = avio_rl32(pb); | |
| 144 | − if (vst->codecpar->bits_per_coded_sample < 0 || | |
| 145 | − vst->codecpar->bits_per_coded_sample > (INT_MAX - 7) / (vst->codecpar->width * vst->codecpar->height)) { | |
| 144 | + bits_per_coded_sample = avio_rl32(pb); | |
| 145 | + if (bits_per_coded_sample > (INT_MAX - 7) / (width * height)) { | |
| 146 | 146 | av_log(avctx, AV_LOG_ERROR, |
| 147 | − "invalid bits_per_coded_sample %d (size: %dx%d)\n", | |
| 148 | − vst->codecpar->bits_per_coded_sample, | |
| 149 | − vst->codecpar->width, vst->codecpar->height); | |
| 147 | + "invalid bits_per_coded_sample %u (size: %ux%u)\n", | |
| 148 | + bits_per_coded_sample, width, height); | |
| 150 | 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 | 154 | avio_skip(pb, 8 + 16 + 24); // black_level, white_level, xywh, active_area, exposure_bias |
| 153 | 155 | if (avio_rl32(pb) != 0x2010100) /* RGGB */ |
| 154 | 156 | avpriv_request_sample(avctx, "cfa_pattern"); |