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

Infinite loop when reading jp2 #1081

Closed
nroduit opened this issue Feb 18, 2018 · 3 comments
Closed

Infinite loop when reading jp2 #1081

nroduit opened this issue Feb 18, 2018 · 3 comments

Comments

@nroduit
Copy link

nroduit commented Feb 18, 2018

With some jp2 images, the decompressor freezes because of an infinite loop in https://github.com/uclouvain/openjpeg/blob/master/src/lib/openjp2/cio.c#L320

I guess those images could have something wrong but this inifinit loop should not exist. Here is a proposal of fix (works with my sample):

diff --git a/lib/penjp2/cio.c b/lib/openjp2/cio.c
index 4fde9fe..7abb2cb 100644
--- a/lib/openjp2/cio.c
+++ b/lib/openjp2/cio.c
@@ -324,7 +324,9 @@
             p_stream->m_bytes_in_buffer = p_stream->m_read_fn(p_stream->m_stored_data,
                                           p_stream->m_buffer_size, p_stream->m_user_data);
 
-            if (p_stream->m_bytes_in_buffer == (OPJ_SIZE_T) - 1) {
+            if (p_stream->m_bytes_in_buffer == 0) {
+            	return 0;
+            } else if (p_stream->m_bytes_in_buffer == (OPJ_SIZE_T) - 1) {
                 /* end of stream */
                 opj_event_msg(p_event_mgr, EVT_INFO, "Stream reached its end !\n");
@boxerab
Copy link
Contributor

boxerab commented Feb 18, 2018

Can you post an image that goes into infinity ?

@kbabioch
Copy link
Contributor

kbabioch commented Mar 2, 2018

@nroduit Could you please provide a reproducer ;)?

@nroduit
Copy link
Author

nroduit commented Mar 4, 2018

I cannot reproduce with the decompress tool. So it should be related to the way I use the API.

I will reopen later if necessary.

@nroduit nroduit closed this as completed Mar 4, 2018
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

No branches or pull requests

3 participants