Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stb_image: fix: load invalid JPEGs #1608 #37

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading