Skip to content

Commit

Permalink
stb_image: fix: load invalid JPEGs #1608 (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
cocoa-xu authored Mar 17, 2024
1 parent 0cb690c commit c69768e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion 3rd_party/stb/stb_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -3437,7 +3437,7 @@ static int stbi__decode_jpeg_image(stbi__jpeg *j)
if (NL != j->s->img_y) return stbi__err("bad DNL height", "Corrupt JPEG");
m = stbi__get_marker(j);
} else {
if (!stbi__process_marker(j, m)) return 1;
if (!stbi__process_marker(j, m)) return stbi__err("bad marker","Corrupt JPEG");
m = stbi__get_marker(j);
}
}
Expand Down
Binary file added test/stb-issue-1608.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions test/stb_image_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,21 @@ defmodule StbImageTest do
end
end
end

describe "bad files" do
test "JPEG with bad maker" do
file = Path.join(__DIR__, "stb-issue-1608.jpg")
binary = File.read!(file)

assert StbImage.read_file(file) == {:error, "cannot decode image"}
assert StbImage.read_binary(binary) == {:error, "cannot decode image"}

assert_raise ArgumentError, "cannot decode image", fn ->
StbImage.read_file!(file)
end
assert_raise ArgumentError, "cannot decode image", fn ->
StbImage.read_binary!(binary)
end
end
end
end

0 comments on commit c69768e

Please sign in to comment.