Piotr Karwasz created IMAGING-397:
-------------------------------------

             Summary: Truncated uncompressed PSD image data decodes without 
error: missing samples read as 0xFF
                 Key: IMAGING-397
                 URL: https://issues.apache.org/jira/browse/IMAGING-397
             Project: Commons Imaging
          Issue Type: Bug
          Components: Format: PSD
    Affects Versions: 1.0.0-alpha6
            Reporter: Piotr Karwasz


{{UncompressedDataReader}} reads {{channels × rows × columns}} samples from the 
image data section through {{MyBitInputStream}}, which returns -1 at the end of 
the stream instead of throwing. The reader does not check for it, so it keeps 
reading until the declared sample count is reached and stores each -1 as 
{{0xFF}}.

A raw (compression 0) PSD whose image data is shorter than its header declares 
therefore decodes through {{Imaging.getBufferedImage}} without any error, with 
the missing pixels set to white. The loop always runs for the full sample count 
declared in the header, however little data the file contains. A truncated 
RLE-compressed PSD, by contrast, is rejected by {{CompressedDataReader}} with 
an {{IOException}} ("PSD: Missing Image Data").

Example: a 3-channel 8-bit RGB PSD declaring 1000×1000 pixels, with a single 
byte of image data, decodes to a white 1000×1000 image.

Suggested fix: throw an {{EOFException}} when the image data ends before the 
declared sample count is reached, as IMAGING-391 does for the TIFF bit reader. 
A pull request with the fix and a test follows.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to