Skip to content

java.lang.ArrayIndexOutOfBoundsException: 17 #1

@helcat

Description

@helcat

I downloaded your folk and built the jar file, the error did not appear but it still did not render the pdf to an image. I Got another error.

java.lang.ArrayIndexOutOfBoundsException: 17
at com.sun.pdfview.PDFImage.biColorToGrayscale(Unknown Source)
at com.sun.pdfview.PDFImage.parseData(Unknown Source)
at com.sun.pdfview.PDFImage.getImage(Unknown Source)
at com.sun.pdfview.PDFImage.parseData(Unknown Source)
at com.sun.pdfview.PDFImage.getImage(Unknown Source)
at com.sun.pdfview.PDFRenderer.drawImage(Unknown Source)
at com.sun.pdfview.PDFImageCmd.execute(Unknown Source)
at com.sun.pdfview.PDFRenderer.iterate(Unknown Source)
at com.sun.pdfview.BaseWatchable.run(Unknown Source)
at com.sun.pdfview.BaseWatchable.execute(Unknown Source)
at com.sun.pdfview.BaseWatchable.go(Unknown Source)
at com.sun.pdfview.PDFPage.getImage(Unknown Source)

I tried other pdfs but anything with layers or shading seems to stacktrace.
Any help would be appreciated.

Your responce :
the issue that you mentioned is a problem with my fork and not related to this bug, since the method "biColorToGrayscale" was introduced by me to speed up the handling of black and white images. Hence, can you please open an new issue on the forks page and attach an example, then I can look at this bug.

Code
byte[] buffer = ((DataBufferByte) converted.getRaster().getDataBuffer()).getData();

int i = 0;
final int height = converted.getHeight();
final int width = converted.getWidth();
for (int y = 0; y < height; y++) {
int base = y_width + 7;
if ((y+1)_width < buffer.length) {
for (int x = 0; x < width; x += 8) {
final byte bits = bufferO[i];
i++;
if (base > buffer.length -1) break; <= ** Added by me just to stop it from crashing I know this is wrong.
buffer[base - 7] = ncc[((bits >>> 7) & 1)];
buffer[base - 6] = ncc[((bits >>> 6) & 1)];
buffer[base - 5] = ncc[((bits >>> 5) & 1)];
buffer[base - 4] = ncc[((bits >>> 4) & 1)];
buffer[base - 3] = ncc[((bits >>> 3) & 1)];
buffer[base - 2] = ncc[((bits >>> 2) & 1)];
buffer[base - 1] = ncc[((bits >>> 1) & 1)];

buffer[base] = ncc[(bits & 1)];


base += 8;
}                   

}
else {
for (int x = 0; x < width; x += 8) {
final byte bits = bufferO[i];
i++;
for (byte j=7; j>=0; j--) {
if (base - j >= buffer.length) break;
buffer[base - j] = ncc[((bits >>> j) & 1)];
}
base += 8;
}
}
}

I know this is wrong but i wanted it yo stop crashing.
if (base > buffer.length -1) break;
With this it renders the image but the colors are wrong.

I dont know how to submit an example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions