History

avformat/mlvdec: Only store dimensions after having validated them

Otherwise it might happen that invalid dimensions are used when reading a video packet; this might lead to undefined overflow.

Andreas Rheinhardt committed 6 years ago

Commit d661cfc1 parent 0d560871 file · +11 −9Browse files

Unified · Split

libavformat/mlvdec.c+11−9
@@ -132,23 +132,25 @@ static int scan_file(AVFormatContext *avctx, AVStream *vst, AVStream *ast, int f · 131 unmodified lines
132132 break;
133133 size -= 16;
134134 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);
138139 if (ret < 0)
139140 return ret;
140141 if (avio_rl32(pb) != 1)
141142 avpriv_request_sample(avctx, "raw api version");
142143 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)) {
146146 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);
150149 return AVERROR_INVALIDDATA;
151150 }
151+ vst->codecpar->width = width;
152+ vst->codecpar->height = height;
153+ vst->codecpar->bits_per_coded_sample = bits_per_coded_sample;
152154 avio_skip(pb, 8 + 16 + 24); // black_level, white_level, xywh, active_area, exposure_bias
153155 if (avio_rl32(pb) != 0x2010100) /* RGGB */
154156 avpriv_request_sample(avctx, "cfa_pattern");

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t