#658: TGAImageReader now allows extension area of size 0

(cherry picked from commit 78817a489b03a3afe372e4bd882b50273fbdd351)
This commit is contained in:
Harald Kuhr 2022-01-19 08:57:49 +01:00
parent 01d6fc8b49
commit e5f6227479
4 changed files with 6 additions and 6 deletions

View File

@ -69,9 +69,7 @@ final class TGAExtensions {
TGAExtensions() {
}
static TGAExtensions read(final ImageInputStream stream) throws IOException {
int extSize = stream.readUnsignedShort();
static TGAExtensions read(final ImageInputStream stream, final int extSize) throws IOException {
// Should always be 495 for version 2.0, no newer version exists.
// NOTE: Known AutoDesk 3ds Max issue, extension area size field is 494, but still good.
if (extSize < EXT_AREA_SIZE - 1) {

View File

@ -411,7 +411,8 @@ final class TGAImageReader extends ImageReaderBase {
if (Arrays.equals(magic, TGA.MAGIC)) {
if (extOffset > 0) {
imageInput.seek(extOffset);
extensions = TGAExtensions.read(imageInput);
int extSize = imageInput.readUnsignedShort();
extensions = extSize == 0 ? null : TGAExtensions.read(imageInput, extSize);
}
}
}

View File

@ -91,12 +91,13 @@ public class TGAImageReaderTest extends ImageReaderAbstractTest<TGAImageReader>
new TestData(getClassLoaderResource("/tga/XING_T24.TGA"), new Dimension(240, 164)), // Uncompressed 24 bit BGR top/down
new TestData(getClassLoaderResource("/tga/XING_T32.TGA"), new Dimension(240, 164)), // Uncompressed 32 bit BGRA top/down
new TestData(getClassLoaderResource("/tga/autodesk-3dsmax-extsize494.tga"), new Dimension(440, 200)), // RLE compressed 32 bit BGRA bottom/up
new TestData(getClassLoaderResource("/tga/autodesk-3dsmax-extsize494.tga"), new Dimension(440, 200)), // RLE compressed 32 bit BGRA bottom/up, with extension area size 494
new TestData(getClassLoaderResource("/tga/monochrome16_top_left.tga"), new Dimension(64, 64)), // Uncompressed 16 bit monochrome
new TestData(getClassLoaderResource("/tga/monochrome16_top_left_rle.tga"), new Dimension(64, 64)), // RLE compressed 16 bit monochrome
new TestData(getClassLoaderResource("/tga/692c33d1-d0c3-4fe2-a059-f199d063bc7a.tga"), new Dimension(256, 256)) // Uncompressed BGR, with colorMapDepth set to 24
new TestData(getClassLoaderResource("/tga/692c33d1-d0c3-4fe2-a059-f199d063bc7a.tga"), new Dimension(256, 256)), // Uncompressed BGR, with colorMapDepth set to 24
new TestData(getClassLoaderResource("/tga/0112eccd-2c29-4368-bcef-59c823b6e5d1.tga"), new Dimension(256, 256)) // RLE compressed BGR, with extension area size 0
);
}