afila / JBIG2-Image-Decoder.NET

A .Net implementation of the Borisvl/JBIG2-Image-Decoder(fork of JPedal's JBIG2 library) with correct MMR decoding
2 stars 0 forks source link

Index out of bounds in JBig2Bitmap.cs #1

Open GBriotti opened 2 years ago

GBriotti commented 2 years ago

I have a problem reading image from pdf.

Basically, in this snippet of code in JBig2Bitmap.cs, method readBitmap(): ` if (typicalPredictionGenericDecodingOn) { int bit = arithmeticDecoder.decodeBit(ltpCX, arithmeticDecoder.genericRegionStats); if (bit != 0) ltp = !ltp;

                    if (ltp) {
                        duplicateRow(row, row - 1);
                        continue;
                    }
                }

` ltp is true but row is zero!

This is the output if debug is set to true: validFile = False ==== Segments ==== ==== Segment Header ==== SegmentNumber = 1 SegmentType = 48 pageAssociationSizeSet = False deferredNonRetainSet = False referredToSegmentCount = 0 retentionFlags = 0 referredToSegments = pageAssociation = 1 dateLength = 19 ==== Page Information Dictionary ==== ==== Reading Page Information Dictionary ==== Bitmap size = 2368x1654 Resolution = 0x0 DEFAULT_PIXEL_VALUE=0 DEFAULT_COMBINATION_OPERATOR=0 symbolDictionaryFlags = 1 Page Striping = 0 ==== Segment Header ==== SegmentNumber = 2 SegmentType = 38 pageAssociationSizeSet = False deferredNonRetainSet = False referredToSegmentCount = 0 retentionFlags = 0 referredToSegments = pageAssociation = 1 dateLength = 22594 ==== Immediate Generic Region ==== ==== Reading Immediate Generic Region ==== Bitmap size = 2368x1654 Bitmap location = 0,0 EXTERNAL_COMBINATION_OPERATOR=0 region Segment flags = 0 MMR=0 GB_TEMPLATE=0 TPGDON=1 generic region Segment flags = 8

GBriotti commented 2 years ago

I've found a solution in a similar project:

if (ltp) { // if the top row needs a predictor, we need to wrap around to the bottom row int target = row - 1; if (target < 0) target = (int)(height - 1); duplicateRow(row, target); continue; }

afila commented 2 years ago

Hi, @GBriotti! Thanks for interesting in JBIG2! Could you send me a pdf caused the error? So that I can test and apply your issue.