Skip to content
New issue

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

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

Already on GitHub? # to your account

Segmentation fault when saving image of size (0, 0) #1018

Closed
charleskawczynski opened this issue Feb 2, 2023 · 2 comments
Closed

Segmentation fault when saving image of size (0, 0) #1018

charleskawczynski opened this issue Feb 2, 2023 · 2 comments

Comments

@charleskawczynski
Copy link

charleskawczynski commented Feb 2, 2023

I recently found that Images.save can segfault if the image is of size (0,0) on Windows with Images v0.25.2. Here's what the error looks like:

julia> import Images

julia> img = Matrix{Images.RGB{Images.N0f8}}(zeros(0, 0))
0×0 Array{RGB{N0f8},2} with eltype ColorTypes.RGB{FixedPointNumbers.N0f8}

julia> Images.save("img.jpg", img)
[ Info: Precompiling JpegTurbo [b835a17e-a41a-41e7-81f0-2f016b05efe0]

Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x1f95e6379b0 -- unknown function (ip: 000001f95e6379b0)
in expression starting at REPL[3]:1
unknown function (ip: 000001f95e6379b0)
Allocations: 16708880 (Pool: 16697445; Big: 11435); GC: 14

Versioninfo:

julia> versioninfo()
Julia Version 1.8.5
Commit 17cfb8e65e (2023-01-08 06:45 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 8 × Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, skylake)
  Threads: 1 on 8 virtual cores
Environment:
  JULIA_PKG_DEVDIR = dev/julia

Copy-paste-friendly mwe:

import Images
img = Matrix{Images.RGB{Images.N0f8}}(zeros(0, 0))
Images.save("img.jpg", img)

Maybe this should be moved into julia base, but I'm unfamiliar with how Images.save works.

@johnnychen94
Copy link
Member

Not sure if it's possible to save empty data using jpeg turbo (my intuition is that JPEG format allows it), a quick patch is to check the size and throw an error eagerly in https://github.com/JuliaIO/JpegTurbo.jl/blob/33d53e772cb3c11c0f49082d6493b06bec6cbaea/src/encode.jl#L86-L87

@johnnychen94
Copy link
Member

johnnychen94 commented Feb 5, 2023

Maybe this should be moved into julia base

Just a side note. Usually, the segfault is due to an incorrect C call and most of them are not Julia issues but library issues. People have to do extensive argument checks before calling the "unsafe" C routine.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants