Skip to content

Commit a50e7c7

Browse files
authored
fix(pdf): Perform endian byteswap on correct buffer area for PSD RLE (#4600)
Perform the endian byteswap on the correct buffer area for PSD RLE decoding. The original code used `dst` but that pointer is modified from its original value as it progresses through decoding. Fixes #4599 --------- Signed-off-by: Jesse Yurkovich <jesse.y@gmail.com>
1 parent e67dcd2 commit a50e7c7

3 files changed

Lines changed: 34 additions & 3 deletions

File tree

src/psd.imageio/psdinput.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,6 +2233,7 @@ PSDInput::decompress_packbits(const char* src, char* dst,
22332233
int16_t header;
22342234
int length;
22352235

2236+
char* dst_start = dst;
22362237
while (src_remaining > 0 && dst_remaining > 0) {
22372238
header = *reinterpret_cast<const signed char*>(src);
22382239
src++;
@@ -2275,8 +2276,8 @@ PSDInput::decompress_packbits(const char* src, char* dst,
22752276

22762277
if (!bigendian()) {
22772278
switch (m_header.depth) {
2278-
case 16: swap_endian((uint16_t*)dst, m_spec.width); break;
2279-
case 32: swap_endian((uint32_t*)dst, m_spec.width); break;
2279+
case 16: swap_endian((uint16_t*)dst_start, m_spec.width); break;
2280+
case 32: swap_endian((uint32_t*)dst_start, m_spec.width); break;
22802281
}
22812282
}
22822283

testsuite/psd/ref/out.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,36 @@ Reading ../oiio-images/psd/psd_rgba_8.psd
805805
stEvt:instanceID: "xmp.iid:037A91A22BCDE011A998CBE7B5CCEB92; xmp.iid:2793235262CFE011B8B8C52D9599FB9E"
806806
stEvt:softwareAgent: "Adobe Photoshop CS5.1 Windows"
807807
stEvt:when: "2011-08-22T22:07:44-04:00; 2011-08-25T17:39:28-04:00"
808+
Reading ../oiio-images/psd/psd_rgb_16_rle.psd
809+
../oiio-images/psd/psd_rgb_16_rle.psd : 3840 x 2160, 3 channel, uint16 psd
810+
SHA-1: CF2071CFD7AF69ECEFC9EA00DC0EA7F8ED6A2E2B
811+
channel list: R, G, B
812+
DateTime: "2025-01-10T23:27:45+02:00"
813+
ICCProfile: 0, 0, 2, 48, 65, 68, 66, 69, 2, 16, 0, 0, 109, 110, 116, 114, ... [560 x uint8]
814+
Orientation: 1 (normal)
815+
PixelAspectRatio: 1
816+
ResolutionUnit: "in"
817+
Software: "Adobe Photoshop 26.0 (Windows)"
818+
thumbnail_height: 90
819+
thumbnail_nchannels: 3
820+
thumbnail_width: 160
821+
XResolution: 72
822+
YResolution: 72
823+
Exif:ColorSpace: 65535
824+
Exif:PixelXDimension: 3840
825+
Exif:PixelYDimension: 2160
826+
IPTC:DocumentID: "xmp.did:9de7a004-9188-384a-a78b-5202a1f8a5ae"
827+
IPTC:InstanceID: "xmp.iid:9de7a004-9188-384a-a78b-5202a1f8a5ae"
828+
IPTC:MetadataDate: "2025-01-10T23:28:11+02:00"
829+
IPTC:ModifyDate: "2025-01-10T23:28:11+02:00"
830+
IPTC:OriginalDocumentID: "xmp.did:9de7a004-9188-384a-a78b-5202a1f8a5ae"
831+
photoshop:ColorMode: 3
832+
photoshop:ICCProfile: "Adobe RGB (1998)"
833+
rdf:parseType: "Resource"
834+
stEvt:action: "created"
835+
stEvt:instanceID: "xmp.iid:9de7a004-9188-384a-a78b-5202a1f8a5ae"
836+
stEvt:softwareAgent: "Adobe Photoshop 26.0 (Windows)"
837+
stEvt:when: "2025-01-10T23:27:45+02:00"
808838
Reading ../oiio-images/psd/psd_123.psd
809839
../oiio-images/psd/psd_123.psd : 257 x 126, 4 channel, uint8 psd
810840
4 subimages: 257x126 [u8,u8,u8,u8], 33x98 [u8,u8,u8,u8], 63x100 [u8,u8,u8,u8], 61x102 [u8,u8,u8,u8]

testsuite/psd/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
files = [ "psd_123.psd", "psd_123_nomaxcompat.psd", "psd_bitmap.psd",
1010
"psd_indexed_trans.psd", "psd_rgb_8.psd", "psd_rgb_16.psd",
11-
"psd_rgb_32.psd", "psd_rgba_8.psd" ]
11+
"psd_rgb_32.psd", "psd_rgba_8.psd", "psd_rgb_16_rle.psd" ]
1212
for f in files:
1313
command += info_command (OIIO_TESTSUITE_IMAGEDIR + "/" + f)
1414

0 commit comments

Comments
 (0)