Skip to content

Commit

Permalink
bugfix: disallow encoding of empty array
Browse files Browse the repository at this point in the history
This might be valid for JPEG specification, but for now it's better
to disallow it so that it doesn't segfault

closes JuliaImages/Images.jl#1018
  • Loading branch information
johnnychen94 committed Feb 5, 2023
1 parent 33d53e7 commit 5963573
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "JpegTurbo"
uuid = "b835a17e-a41a-41e7-81f0-2f016b05efe0"
authors = ["Johnny Chen <[email protected]>"]
version = "0.1.1"
version = "0.1.2"

[deps]
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
Expand Down
4 changes: 4 additions & 0 deletions src/encode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ function _encode(
Y_density::Union{Nothing,Int} = nothing,
write_Adobe_marker::Union{Nothing,Bool} = nothing
)
if prod(size(img)) == 0
throw(ArgumentError("empty image is not allowed"))
end

cinfo = LibJpeg.jpeg_compress_struct()
cinfo_ref = Ref(cinfo)
jerr = Ref{LibJpeg.jpeg_error_mgr}()
Expand Down
2 changes: 2 additions & 0 deletions test/tst_encode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ img_rgb = testimage("lighthouse")
img_or = 1.5 .* img
img_or[1] = Gray(NaN)
@test jpeg_encode(img_or) == jpeg_encode(Float64.(img_or)) == jpeg_encode(clamp01nan!(img_or))

@test_throws ArgumentError("empty image is not allowed") jpeg_encode(Array{Float64,2}(undef, 0, 0))
end

# keyword checks
Expand Down

2 comments on commit 5963573

@johnnychen94
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/77041

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.2 -m "<description of version>" 5963573a0f0a6f8d137df00349bc8f7634664cb7
git push origin v0.1.2

Please sign in to comment.