Skip to content

Conversation

@mariusherzog
Copy link

Under certain circumstances, an invalid JPEG2000 file, ie. when an EOC marker is encountered before any SOT marker, leads to an endless loop when trying to parse the header in opj_read_header.
Attached is a file where this error occurs.
invalid.debug

@rouault
Copy link
Collaborator

rouault commented Nov 21, 2025

Attached is a file where this error occurs.

I can't reproduce any hang with latest openjpeg master:

$ ./bin/opj_decompress  -i ~/Téléchargements/invalid.debug -o out.ppm

===========================================
The extension of this file is incorrect.
FOUND ebug. SHOULD BE .j2k or .jpc or .j2c or .jhc
===========================================

[INFO] Start to read j2k main header (0).
[WARNING] Unknown marker
[INFO] Stream reached its end !
[ERROR] Stream too short
[ERROR] Unknown marker has been detected and generated error.
ERROR -> opj_decompress: failed to read the header

@mariusherzog
Copy link
Author

There was a subtle bug in my opj_stream_set_read_function which did not correctly detect the end-of-stream in this case. Sorry for the inconvenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants