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

JP2000 -pS (print Structure) throws 'Invalid slice bounds specified' on all jp2 files. #744

Closed
clanmills opened this issue Mar 15, 2019 · 0 comments
Assignees
Milestone

Comments

@clanmills
Copy link
Collaborator

There's an issue in Jp2Image::printStructure() causing an exception when we dump the header structure. This was reported in #740 and @D4N requested that it be logged separately.

$ for i in test/data/*.jp2 ; do exiv2 -pS $i; done
STRUCTURE OF JPEG2000 FILE: test/data/Reagan.jp2
 address |   length | box       | data
       0 |       12 | jP        | 
      12 |       20 | ftyp      | 
      32 |       45 | jp2h      | 
      40 |       22 |  sub:ihdr | Uncaught exception: Invalid slice bounds specified
STRUCTURE OF JPEG2000 FILE: test/data/Reagan2.jp2
 address |   length | box       | data
       0 |       12 | jP        | 
      12 |       20 | ftyp      | 
      32 |     3185 | jp2h      | 
      40 |       22 |  sub:ihdr | Uncaught exception: Invalid slice bounds specified
STRUCTURE OF JPEG2000 FILE: test/data/relax.jp2
 address |   length | box       | data
       0 |       12 | jP        | 
      12 |       20 | ftyp      | 
      32 |      345 | jp2h      | 
      40 |       22 |  sub:ihdr | Uncaught exception: Invalid slice bounds specified
706 rmills@rmillsmbp:~/gnu/github/exiv2/0.27-maintenance $ 

This appears to be caused by the '30' passed to makeSlice() when there are less than 30 bytes in data.buf_

My fix is:

diff --git a/src/jp2image.cpp b/src/jp2image.cpp
index 39a6f58..80d1ec2 100644
--- a/src/jp2image.cpp
+++ b/src/jp2image.cpp
@@ -508,9 +508,11 @@ namespace Exiv2
                             DataBuf data(subBox.length-sizeof(box));
                             io_->read(data.pData_,data.size_);
                             if ( bPrint ) {
+                                size_t ssize = data.size_;
+                                if   ( ssize > 30 ) ssize = 30; // limit the binary data presentation to 30 bytes
                                 out << Internal::stringFormat("%8ld | %8ld |  sub:",(size_t)address,(size_t)subBox.length)
                                     << toAscii(subBox.type)
-                                    <<" | " << Internal::binaryToString(makeSlice(data, 0, 30));
+                                    <<" | " << Internal::binaryToString(makeSlice(data, 0, ssize));
                                 bLF = true;
                             }
 
707 rmills@rmillsmbp:~/gnu/github/exiv2/0.27-maintenance $ 

With this fix, the output is:

.../exiv2/0.27-maintenance $ for i in test/data/*.jp2 ; do  cmake-build-debug/bin/exiv2 -pS $i; done
STRUCTURE OF JPEG2000 FILE: test/data/Reagan.jp2
 address |   length | box       | data
       0 |       12 | jP        | 
      12 |       20 | ftyp      | 
      32 |       45 | jp2h      | 
      40 |       22 |  sub:ihdr | .............
      62 |       15 |  sub:colr | ....... | pad: 1 0 0 | iccLength:16
      77 |     1342 | uuid      | Exif: II*...........................>........
    1419 |      942 | uuid      | IPTC: ............040621-N-6536T-062.....5...
    2361 |     5590 | uuid      | XMP : <?xpacket begin="..." id="W5M0MpCehiHzre
    7951 |    32658 | jp2c      | 
STRUCTURE OF JPEG2000 FILE: test/data/Reagan2.jp2
 address |   length | box       | data
       0 |       12 | jP        | 
      12 |       20 | ftyp      | 
      32 |     3185 | jp2h      | 
      40 |       22 |  sub:ihdr | .............
      62 |     3155 |  sub:colr | ......HLino....mntrRGB XYZ .. | pad: 2 0 0 | iccLength:3144
    3217 |        0 | jp2c      | 
STRUCTURE OF JPEG2000 FILE: test/data/relax.jp2
 address |   length | box       | data
       0 |       12 | jP        | 
      12 |       20 | ftyp      | 
      32 |      345 | jp2h      | 
      40 |       22 |  sub:ihdr | ...,.........
      62 |      289 |  sub:colr | ............ ..scnrRGB XYZ .. | pad: 2 0 0 | iccLength:278
     351 |       26 |  sub:res  | ....resc$I..$I....
     377 |        0 | jp2c      | 
708 rmills@rmillsmbp:~/gnu/github/exiv2/0.27-maintenance $ 

This fault applies to both 'master' and '0.27-maintenance'.

@clanmills clanmills added this to the v0.27.1 milestone Mar 15, 2019
@clanmills clanmills self-assigned this Mar 15, 2019
@piponazo piponazo mentioned this issue Apr 7, 2019
D4N pushed a commit that referenced this issue Apr 8, 2019
1div0 pushed a commit to 1div0/exiv2 that referenced this issue May 5, 2019
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

1 participant