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

TIFFLZWDecompressor Null Pointer Exception #37

Open
reeperbahnause opened this issue May 13, 2017 · 6 comments
Open

TIFFLZWDecompressor Null Pointer Exception #37

reeperbahnause opened this issue May 13, 2017 · 6 comments

Comments

@reeperbahnause
Copy link

Hi,

I stumbled across an issue while using ZXing try to read the attached TIFF file 00000_001.zip.

The following Exception occurs as soon as the image should be read:

Exception in thread "main" java.lang.NullPointerException
        at com.github.jaiimageio.impl.plugins.tiff.TIFFLZWDecompressor.addStringToTable(TIFFLZWDecompressor.java:246)
        at com.github.jaiimageio.impl.plugins.tiff.TIFFLZWDecompressor.decode(TIFFLZWDecompressor.java:183)
        at com.github.jaiimageio.impl.plugins.tiff.TIFFLZWDecompressor.decodeRaw(TIFFLZWDecompressor.java:131)
        at com.github.jaiimageio.plugins.tiff.TIFFDecompressor.decode(TIFFDecompressor.java:2583)
        at com.github.jaiimageio.impl.plugins.tiff.TIFFImageReader.decodeTile(TIFFImageReader.java:1144)
        at com.github.jaiimageio.impl.plugins.tiff.TIFFImageReader.read(TIFFImageReader.java:1414)
        at javax.imageio.ImageIO.read(Unknown Source)
        at javax.imageio.ImageIO.read(Unknown Source)
        at com.google.zxing.client.j2se.ImageReader.readImage(ImageReader.java:44)
        at com.google.zxing.client.j2se.DecodeWorker.decode(DecodeWorker.java:120)
        at com.google.zxing.client.j2se.DecodeWorker.call(DecodeWorker.java:76)
        at com.google.zxing.client.j2se.CommandLineRunner.main(CommandLineRunner.java:98)

The command line I was testing is the following:

java -classpath .;jai-imageio-core-1.3.1.jar;jcommander-1.69.jar;javase-3.3.0.jar;core-3.3.1.jar com.google.zxing.client.j2se.CommandLineRunner file:////home/phillip/repository/Uploads/5916bdab80775/Optimized --possible_formats CODE_39 CODE_128 ITF --recursive --try_harder --multi

I just cloned the project to see if I can get any additional information about the exception but so far this is what I have.

@reeperbahnause
Copy link
Author

Just created and tested the jai-imageio-core-1.3.2-SNAPSHOT.jar with the same result.

@lbellonda
Copy link
Member

Hello the problem is in the support to LSB TIFF. The input stream is always read as it was MSB coded.
LSB images are not so common among TIFF.
A patch is needed to getNextCode method of TIFFLZWDecompressor class to support LSB files.

@reeperbahnause
Copy link
Author

Hi,
I was debugging a bit an noticed in this line

addStringToTable(stringTable[oldCode], string[0]);

that the oldCode is > than 258 and because of that the returned value from the stringTable is null

I'm neither familiar with the decoding process nor the algorhythm and so probably the wrong person to contribute.
I would just like to help and let you know how I created this TIFF file.
The original file is a PDF document which I converted to a TIFF file using ImageMagicks convert tool.

convert -background white -alpha remove -scene 1 -density 300 -compress LZW -type grayscale -depth 8 /home/user/source.file /home/user/%03d.tif

After that I testet the Barcode extraction using Zxing which was working totally fine.
Then accidentally I was testing the barcode extraction using the TIFF file, which was converted a second time using ImageMagicks convert tool with the same parameters.
This twice converted TIFF file is the image I attached to this issue.

@lbellonda
Copy link
Member

that the oldCode is > than 258 and because of
This is the effect of the misinterpretation of the input data in getNextCode() with LSB images.
"stringTable" entries should grow with the decompression process.

lbellonda added a commit to lbellonda/jai-imageio-core that referenced this issue May 20, 2017
@lbellonda
Copy link
Member

Hello, I am working on a fix on my fork: https://github.com/lbellonda/jai-imageio-core/tree/issue37
It still needs some optimization, but it is working with your image by checking the TIFF tag "FillOrder".

lbellonda added a commit to lbellonda/jai-imageio-core that referenced this issue May 24, 2017
stain added a commit that referenced this issue Apr 10, 2018
Adds support for LSB-encoded TIFF images.
Fixes issue #37 (?)
@stain
Copy link
Member

stain commented Apr 10, 2018

Thanks for your contribution, @lbellonda, I've merged #39.

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