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

cjxl - temp JPEG files remain #6

Closed
eddiezato opened this issue May 26, 2021 · 18 comments · Fixed by #300
Closed

cjxl - temp JPEG files remain #6

eddiezato opened this issue May 26, 2021 · 18 comments · Fixed by #300
Labels
building/portability Platform-specific issues, build issues cjxl Related to cjxl encoder tool

Comments

@eddiezato
Copy link

If the input files are JPEGs, cjxl creates jpe????.tmp files in the system %temp% folder and doesn't delete them after the encoding is finished.

Windows 10 20H2 x64, cjxl v0.3.7-12-g04267a8

@jonsneyers
Copy link
Member

I wonder what is creating these temp files. I don't think jxl itself does that; perhaps libjpeg does it for some reason?

Scope on discord pointed to https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/example.txt#L208 which might be an explanation.

@jonsneyers jonsneyers added cjxl Related to cjxl encoder tool building/portability Platform-specific issues, build issues labels May 26, 2021
@JamesPous
Copy link

I recognized the same problem with jpe*.tmp files with the cjxl.exe (JPEG XL encoder 0.3.7) under Windows 10 64bit (lastest updates).

@eustas
Copy link
Contributor

eustas commented Jul 5, 2021

"On some systems you may need to set up a signal handler to ensure that temporary files are deleted if the program is interrupted. See libjpeg.txt."

@eustas
Copy link
Contributor

eustas commented Jul 5, 2021

But: "NOTE: Unless you develop your own memory manager back end, then temporary files
will never be used. The back end provided in libjpeg-turbo (jmemnobs.c) simply
malloc()s and free()s virtual arrays, and an error occurs if the required
memory exceeds the limit specified in cinfo->mem->max_memory_to_use."

@eddiezato
Copy link
Author

It's best to use the memory manager jmemnobs.c if you can (ie, if you have enough real or virtual main memory). If not, at least make sure that max_memory_to_use is set as high as possible. If the JPEG memory manager has to use a temporary file, you will probably see a lot of disk traffic and poor performance.

Probably max_memory_to_use isn't used and defaults to 0. This forces the encoder to create temp files every time.
I even tried 1-pixel jpeg. Same thing.

@eustas
Copy link
Contributor

eustas commented Jul 5, 2021

So, it is easily reproducible? Good! Does it create file even if processing was successful?
(going to try to reproduce myself, but will bother you further if won't succeed).

@eddiezato
Copy link
Author

eddiezato commented Jul 5, 2021

Even a simple cjxl 0.jpg will create a temp file that's just a copy of the input jpeg. On Windows at least.

Does it create file even if processing was successful?

It always creates temp files, regardless of whether the process was successful or failed.

@eustas
Copy link
Contributor

eustas commented Jul 6, 2021

Spent some time trying to build project on windows, with limited success (got binary that does not support JPEG).
(Hmm, we have to improve that story - vcpkg and chocolatey is a must).

Next, built binaries via cross-compilation in docker container. Those, however work fine and does not create temporay files.

@eddiezato could you share your experience, how you build / obtain the cjxl / djxl binaries, please.

@eddiezato
Copy link
Author

eddiezato commented Jul 6, 2021

I build with mingw64/msys2 myself.
Share them here https://eddiezato.github.io/bin/

#!/bin/bash
export CC=clang CXX=clang++
git clone https://github.com/libjxl/libjxl.git --recursive
cd libjxl
./deps.sh
cmake -B build -G Ninja -S ./ \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_TESTING=OFF \
    -DJPEGXL_ENABLE_DEVTOOLS=ON \
    -DJPEGXL_ENABLE_OPENEXR=OFF \
    -DJPEGXL_ENABLE_SKCMS=OFF \
    -DJPEGXL_ENABLE_BENCHMARK=OFF \
    -DJPEGXL_WARNINGS_AS_ERRORS=OFF \
    -DJPEGXL_STATIC=ON \
    -DCMAKE_CXX_FLAGS='-ffunction-sections -fdata-sections' \
    -DCMAKE_EXE_LINKER_FLAGS='-Wl,--gc-sections -Wl,--no-export-dynamic'
ninja -C build
strip -s build/tools/{cjxl.exe,djxl.exe}

@eddiezato
Copy link
Author

I haven't thought about it. But it could be a problem with the mingw package for libjpeg-turbo. If it turns out that the problem occurs only on mingw builds.

@eustas
Copy link
Contributor

eustas commented Jul 6, 2021

At last, succeeded with MSYS2 / mingw-w64-x86_64-clang.
Can't reproduce =(

@eustas
Copy link
Contributor

eustas commented Jul 6, 2021

(oh, but perhaps I have no libjpeg-turbo installed)

@eustas
Copy link
Contributor

eustas commented Jul 6, 2021

@eustas
Copy link
Contributor

eustas commented Jul 6, 2021

Tried building without libjpeg-turbo... same result.

@eddiezato
Copy link
Author

This also happens if the input jpeg is not valid, not even jpg. 😀

PS > ls -Path $Env:temp\jpe*.tmp
PS > Rename-Item cjxl.exe cjxl.jpg
PS > cjxl cjxl.jpg
JPEG XL encoder v0.3.7 [SSE4]
Failed to read image cjxl.jpg.
PS > ls -Path $Env:temp\jpe*.tmp

    Directory: Z:\Temp

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---          2021.07.07     8:55        6641152 jpeD8F3.tmp

@eustas
Copy link
Contributor

eustas commented Jul 8, 2021

Pinpointed the problem. It is: 🤦 🙀
Will fix soon.

@eustas
Copy link
Contributor

eustas commented Jul 8, 2021

(and it have nothing to do with JPEG)

@eddiezato
Copy link
Author

@eustas I checked #300 , no temp files. Thanks 👍

eustas added a commit to eustas/libjxl that referenced this issue Apr 7, 2022
```
xvfb-run -a ./build/plugins/gdk-pixbuf/pixbufloader_test ./plugins/gdk-pixbuf/loaders_test.cache ./third_party/testdata/jxl/blending/cropped_traffic_light.jxl
Uninitialized bytes in __interceptor_strlen at offset 10 inside [0x701000000810, 11)
==3746300==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x7f09809c906e in _XlcAddCT (/lib/x86_64-linux-gnu/libX11.so.6+0x5306e)
    #1 0x7f09809c92f7 in _XlcInitCTInfo (/lib/x86_64-linux-gnu/libX11.so.6+0x532f7)
    libjxl#2 0x7f09809cf482  (/lib/x86_64-linux-gnu/libX11.so.6+0x59482)
    libjxl#3 0x7f09809ceb62  (/lib/x86_64-linux-gnu/libX11.so.6+0x58b62)
    libjxl#4 0x7f09809cf378 in _XlcCreateLC (/lib/x86_64-linux-gnu/libX11.so.6+0x59378)
    libjxl#5 0x7f09809f0070 in _XlcUtf8Loader (/lib/x86_64-linux-gnu/libX11.so.6+0x7a070)
    libjxl#6 0x7f09809d690d in _XOpenLC (/lib/x86_64-linux-gnu/libX11.so.6+0x6090d)
    libjxl#7 0x7f09809d6a58 in XSupportsLocale (/lib/x86_64-linux-gnu/libX11.so.6+0x60a58)
    libjxl#8 0x7f098191b5b6  (/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0+0x625b6)
    libjxl#9 0x7f0981920158  (/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0+0x67158)
    libjxl#10 0x7f09818d79ba in gdk_parse_args (/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0+0x1e9ba)
    libjxl#11 0x7f09818d7ba8 in gdk_init_check (/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0+0x1eba8)
    libjxl#12 0x562d08176fb2 in main libjxl/plugins/gdk-pixbuf/pixbufloader_test.cc:26:8
    libjxl#13 0x7f0980d617fc in __libc_start_main csu/../csu/libc-start.c:332:16
    libjxl#14 0x562d08100219 in _start (libjxl/build/plugins/gdk-pixbuf/pixbufloader_test+0x21219)

  Uninitialized value was created by a heap allocation
    #0 0x562d08124f0d in malloc (libjxl/build/plugins/gdk-pixbuf/pixbufloader_test+0x45f0d)
    #1 0x7f09809c96cd in _XlcCreateDefaultCharSet (/lib/x86_64-linux-gnu/libX11.so.6+0x536cd)

SUMMARY: MemorySanitizer: use-of-uninitialized-value (/lib/x86_64-linux-gnu/libX11.so.6+0x5306e) in _XlcAddCT
```
eustas added a commit that referenced this issue Apr 7, 2022
```
xvfb-run -a ./build/plugins/gdk-pixbuf/pixbufloader_test ./plugins/gdk-pixbuf/loaders_test.cache ./third_party/testdata/jxl/blending/cropped_traffic_light.jxl
Uninitialized bytes in __interceptor_strlen at offset 10 inside [0x701000000810, 11)
==3746300==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x7f09809c906e in _XlcAddCT (/lib/x86_64-linux-gnu/libX11.so.6+0x5306e)
    #1 0x7f09809c92f7 in _XlcInitCTInfo (/lib/x86_64-linux-gnu/libX11.so.6+0x532f7)
    #2 0x7f09809cf482  (/lib/x86_64-linux-gnu/libX11.so.6+0x59482)
    #3 0x7f09809ceb62  (/lib/x86_64-linux-gnu/libX11.so.6+0x58b62)
    #4 0x7f09809cf378 in _XlcCreateLC (/lib/x86_64-linux-gnu/libX11.so.6+0x59378)
    #5 0x7f09809f0070 in _XlcUtf8Loader (/lib/x86_64-linux-gnu/libX11.so.6+0x7a070)
    #6 0x7f09809d690d in _XOpenLC (/lib/x86_64-linux-gnu/libX11.so.6+0x6090d)
    #7 0x7f09809d6a58 in XSupportsLocale (/lib/x86_64-linux-gnu/libX11.so.6+0x60a58)
    #8 0x7f098191b5b6  (/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0+0x625b6)
    #9 0x7f0981920158  (/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0+0x67158)
    #10 0x7f09818d79ba in gdk_parse_args (/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0+0x1e9ba)
    #11 0x7f09818d7ba8 in gdk_init_check (/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0+0x1eba8)
    #12 0x562d08176fb2 in main libjxl/plugins/gdk-pixbuf/pixbufloader_test.cc:26:8
    #13 0x7f0980d617fc in __libc_start_main csu/../csu/libc-start.c:332:16
    #14 0x562d08100219 in _start (libjxl/build/plugins/gdk-pixbuf/pixbufloader_test+0x21219)

  Uninitialized value was created by a heap allocation
    #0 0x562d08124f0d in malloc (libjxl/build/plugins/gdk-pixbuf/pixbufloader_test+0x45f0d)
    #1 0x7f09809c96cd in _XlcCreateDefaultCharSet (/lib/x86_64-linux-gnu/libX11.so.6+0x536cd)

SUMMARY: MemorySanitizer: use-of-uninitialized-value (/lib/x86_64-linux-gnu/libX11.so.6+0x5306e) in _XlcAddCT
```
Daasin pushed a commit to FOSS-Archives/libjxl that referenced this issue May 17, 2022
```
xvfb-run -a ./build/plugins/gdk-pixbuf/pixbufloader_test ./plugins/gdk-pixbuf/loaders_test.cache ./third_party/testdata/jxl/blending/cropped_traffic_light.jxl
Uninitialized bytes in __interceptor_strlen at offset 10 inside [0x701000000810, 11)
==3746300==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x7f09809c906e in _XlcAddCT (/lib/x86_64-linux-gnu/libX11.so.6+0x5306e)
    #1 0x7f09809c92f7 in _XlcInitCTInfo (/lib/x86_64-linux-gnu/libX11.so.6+0x532f7)
    #2 0x7f09809cf482  (/lib/x86_64-linux-gnu/libX11.so.6+0x59482)
    libjxl#3 0x7f09809ceb62  (/lib/x86_64-linux-gnu/libX11.so.6+0x58b62)
    libjxl#4 0x7f09809cf378 in _XlcCreateLC (/lib/x86_64-linux-gnu/libX11.so.6+0x59378)
    libjxl#5 0x7f09809f0070 in _XlcUtf8Loader (/lib/x86_64-linux-gnu/libX11.so.6+0x7a070)
    libjxl#6 0x7f09809d690d in _XOpenLC (/lib/x86_64-linux-gnu/libX11.so.6+0x6090d)
    libjxl#7 0x7f09809d6a58 in XSupportsLocale (/lib/x86_64-linux-gnu/libX11.so.6+0x60a58)
    libjxl#8 0x7f098191b5b6  (/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0+0x625b6)
    libjxl#9 0x7f0981920158  (/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0+0x67158)
    libjxl#10 0x7f09818d79ba in gdk_parse_args (/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0+0x1e9ba)
    libjxl#11 0x7f09818d7ba8 in gdk_init_check (/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0+0x1eba8)
    libjxl#12 0x562d08176fb2 in main libjxl/plugins/gdk-pixbuf/pixbufloader_test.cc:26:8
    libjxl#13 0x7f0980d617fc in __libc_start_main csu/../csu/libc-start.c:332:16
    libjxl#14 0x562d08100219 in _start (libjxl/build/plugins/gdk-pixbuf/pixbufloader_test+0x21219)

  Uninitialized value was created by a heap allocation
    #0 0x562d08124f0d in malloc (libjxl/build/plugins/gdk-pixbuf/pixbufloader_test+0x45f0d)
    #1 0x7f09809c96cd in _XlcCreateDefaultCharSet (/lib/x86_64-linux-gnu/libX11.so.6+0x536cd)

SUMMARY: MemorySanitizer: use-of-uninitialized-value (/lib/x86_64-linux-gnu/libX11.so.6+0x5306e) in _XlcAddCT
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
building/portability Platform-specific issues, build issues cjxl Related to cjxl encoder tool
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants