Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="alhuda, Gary Gregory">Fix int overflow in PCX image buffer sizing, now throws AllocationRequestException (#552).</action>
<action type="fix" dev="ggregory" due-to="alhuda, Gary Gregory">Fix int overflow in Allocator.array/arrayList size checks (#551).</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Add messages when throwing NullPointerException.</action>
<action issue="IMAGING-398" type="fix" dev="pkarwasz" due-to="Piotr P. Karwasz, Gary Gregory">Check the byte size of the RGBE pixel buffer and fix int overflow in its sizing, now throws AllocationRequestException (#581).</action>
<!-- ADD -->
<action type="fix" dev="ggregory" due-to="Sean R, Gary Gregory">Add unit tests (#553).</action>
<!-- UPDATE -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ float[][] getPixelData() throws IOException, ImagingException {
}
final byte[] scanLineBytes = ByteConversions.toBytes((short) wd, ByteOrder.BIG_ENDIAN);
final byte[] rgbe = Allocator.byteArray(wd * 4);
final float[][] out = new float[3][Allocator.check(wd * ht)];
final float[][] out = new float[3][Allocator.check((long) wd * ht, 3 * Float.BYTES)];
for (int i = 0; i < ht; i++) {
BinaryFunctions.readAndVerifyBytes(in, TWO_TWO, "Scan line " + i + " expected to start with 0x2 0x2");
BinaryFunctions.readAndVerifyBytes(in, scanLineBytes, "Scan line " + i + " length expected");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@
import org.apache.commons.imaging.ImageInfo;
import org.apache.commons.imaging.ImagingException;
import org.apache.commons.imaging.bytesource.ByteSource;
import org.apache.commons.imaging.common.AllocationRequestException;
import org.apache.commons.imaging.common.ImageMetadata;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

public class RgbeParserTest {

Expand Down Expand Up @@ -91,6 +94,21 @@ public void testInvalidResolutionString() {
assertThrows(ImagingException.class, () -> parser.getImageSize(ByteSource.array(bytes), new RgbeImagingParameters()));
}

/**
* Tests that the size of the float pixel buffer is checked in bytes and without int overflow.
*/
@ParameterizedTest
@ValueSource(strings = {
// 3 float arrays of 100,000,000 pixels: 1.2 GB, above the default 1 GiB limit
"-Y 100000000 +X 1",
// 2 * 1073741824 overflows int
"-Y 1073741824 +X 2" })
void testPixelBufferExceedsAllocationLimit(final String resolution) {
final RgbeImageParser parser = new RgbeImageParser();
final byte[] bytes = ("#?RADIANCE\n\n" + resolution + "\n").getBytes(StandardCharsets.US_ASCII);
assertThrows(AllocationRequestException.class, () -> parser.getBufferedImage(ByteSource.array(bytes), new RgbeImagingParameters()));
}

@Test
public void testRgbeImageParserBasics() {
final RgbeImageParser parser = new RgbeImageParser();
Expand Down
Loading