History

Add missing overflow checks in av_image_fill_pointers() and av_image_fill_linesizes().

Originally committed as revision 25861 to svn://svn.ffmpeg.org/ffmpeg/trunk

Stefano Sabatini committed 15 years ago

Commit 93980241 parent 3694ac21 file · +12 −1Browse files

Unified · Split

libavcore/imgutils.c+12−1
@@ -71,6 +71,8 @@ int av_image_fill_linesizes(int linesizes[4], enum PixelFormat pix_fmt, int widt · 70 unmodified lines
7171 return AVERROR(EINVAL);
7272
7373 if (desc->flags & PIX_FMT_BITSTREAM) {
74+ if (width > (INT_MAX -7) / (desc->comp[0].step_minus1+1))
75+ return AVERROR(EINVAL);
7476 linesizes[0] = (width * (desc->comp[0].step_minus1+1) + 7) >> 3;
7577 return 0;
7678 }
@@ -78,7 +80,10 @@ int av_image_fill_linesizes(int linesizes[4], enum PixelFormat pix_fmt, int widt · 1 unmodified line
7880 av_image_fill_max_pixsteps(max_step, max_step_comp, desc);
7981 for (i = 0; i < 4; i++) {
8082 int s = (max_step_comp[i] == 1 || max_step_comp[i] == 2) ? desc->log2_chroma_w : 0;
81− linesizes[i] = max_step[i] * (((width + (1 << s) - 1)) >> s);
83+ int shifted_w = ((width + (1 << s) - 1)) >> s;
84+ if (max_step[i] > INT_MAX / shifted_w)
85+ return AVERROR(EINVAL);
86+ linesizes[i] = max_step[i] * shifted_w;
8287 }
8388
8489 return 0;
@@ -98,6 +103,8 @@ int av_image_fill_pointers(uint8_t *data[4], enum PixelFormat pix_fmt, int heigh · 13 unmodified lines
98103 return AVERROR(EINVAL);
99104
100105 data[0] = ptr;
106+ if (linesizes[0] > (INT_MAX - 1024) / height)
107+ return AVERROR(EINVAL);
101108 size[0] = linesizes[0] * height;
102109
103110 if (desc->flags & PIX_FMT_PAL) {
@@ -114,7 +121,11 @@ int av_image_fill_pointers(uint8_t *data[4], enum PixelFormat pix_fmt, int heigh · 10 unmodified lines
114121 int h, s = (i == 1 || i == 2) ? desc->log2_chroma_h : 0;
115122 data[i] = data[i-1] + size[i-1];
116123 h = (height + (1 << s) - 1) >> s;
124+ if (linesizes[i] > INT_MAX / h)
125+ return AVERROR(EINVAL);
117126 size[i] = h * linesizes[i];
127+ if (total_size > INT_MAX - size[i])
128+ return AVERROR(EINVAL);
118129 total_size += size[i];
119130 }
120131

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