Skip to content

Commit

Permalink
stb_image: Reject fractional JPEG component subsampling ratios
Browse files Browse the repository at this point in the history
The component resamplers are not written to support this and I've
never seen it happen in a real (non-crafted) JPEG file so I'm
fine rejecting this as outright corrupt.

Fixes issue nothings#1178.
  • Loading branch information
rygorous committed Jul 26, 2021
1 parent c404b78 commit 5ba0baa
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions stb_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -3267,6 +3267,13 @@ static int stbi__process_frame_header(stbi__jpeg *z, int scan)
if (z->img_comp[i].v > v_max) v_max = z->img_comp[i].v;
}

// check that plane subsampling factors are integer ratios; our resamplers can't deal with fractional ratios
// and I've never seen a non-corrupted JPEG file actually use them
for (i=0; i < s->img_n; ++i) {
if (h_max % z->img_comp[i].h != 0) return stbi__err("bad H","Corrupt JPEG");
if (v_max % z->img_comp[i].v != 0) return stbi__err("bad V","Corrupt JPEG");
}

// compute interleaved mcu info
z->img_h_max = h_max;
z->img_v_max = v_max;
Expand Down

0 comments on commit 5ba0baa

Please sign in to comment.