openjpeg
openjpeg copied to clipboard
Partial (non-strict) decoding does not work with multi-threading
Expected behavior and actual behavior.
Expected behavior: file decodes and outputs a solid gray image to out.ppm
Actual behavior: program terminates with exit code 1
Steps to reproduce the problem.
Single-threaded, works:
$ opj_decompress -allow-partial -i in.j2k -o out.ppm
[INFO] Start to read j2k main header (0).
[INFO] Main header has been correctly decoded.
[INFO] No decoded area parameters, set the decoded area to the whole image
[WARNING] Tile part length size inconsistent with stream length
[INFO] Stream reached its end !
[INFO] Header of tile 1 / 1 has been read.
[WARNING] read: segment too long (8192) with max (0) for codeblock 0 (p=0, b=0, r=0, c=0)
[INFO] Generated Outfile out.ppm
decode time: 1038 ms
Multi-threaded, not working:
$ opj_decompress -threads ALL_CPUS -allow-partial -i 1m.j2k -o out.ppm
[INFO] Start to read j2k main header (0).
[INFO] Main header has been correctly decoded.
[INFO] No decoded area parameters, set the decoded area to the whole image
[WARNING] Tile part length size inconsistent with stream length
[INFO] Stream reached its end !
[INFO] Header of tile 1 / 1 has been read.
[WARNING] read: segment too long (8192) with max (0) for codeblock 0 (p=0, b=0, r=0, c=0)
[ERROR] Malformed HT codeblock. Invalid codeblock length values: 0 0 0 1
[ERROR] Failed to decode.
[ERROR] Failed to decode tile 1/1
ERROR -> opj_decompress: failed to decode image!
GitHub doesn't seem to allow attaching files so I have base64 encoded a minimal 139 byte example below:
base64 -d <<EOF > in.j2k
/0//UQAvQAAAAA8AAAAIcAAAAAAAAAAAAAAPAAAACHAAAAAAAAAAAAADDwEBDwEBDwEB/1AACAAC
AAAADf9SAAwAAgABAQUEBEAB/1wAEyCYoKCooKCooKCooKCgmJig/2QAFgABT3BlbkpQSCBWZXIg
MC43LjMu/5AACgAAAWbMIwAB/5PgAAb/dA==
EOF
Pretty much any truncated j2k file replicates the behavior.
Operating system
Debian GNU/Linux 11 (bullseye)
openjpeg version
Current master (52927287402a9f7353de8854c88f931051211e2f)