Skip to content

Commit ce03d56

Browse files
authored
PSD reading: don't reject padded thumbnails (#3677)
When reading PSD file, if reading the thumbnail doesn't pass basic sanity checks, we consider that a hard error reading the file. One check that we do is to make sure that our computation of the byte width of the uncompressed thumbnail (`bpp/8 * width`) matches what the file says the `widthbytes` is. BUT... it seems that it might round up to an even (or maybe 4-multiple?) of columns, presumably for scanline alignment reasons. And so we were considering whole PDF files unreadable if they fell into this case. This PR primarily loosens the test to allow some padding up to a multiple of 4. Fixes #3658
1 parent 209c1bf commit ce03d56

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/psd.imageio/psdinput.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ PSDInput::load_resource_thumbnail(uint32_t length, bool isBGR)
12821282
bpp);
12831283
return false;
12841284
}
1285-
if ((bpp / 8) * width != widthbytes) {
1285+
if ((bpp / 8) * width > widthbytes || (bpp / 8) * width + 3 < widthbytes) {
12861286
errorfmt("Corrupt thumbnail: {}w * {}bpp does not match {} width bytes",
12871287
width, bpp, widthbytes);
12881288
return false;
@@ -1311,9 +1311,10 @@ PSDInput::load_resource_thumbnail(uint32_t length, bool isBGR)
13111311
m_thumbnail.read(0, 0, true);
13121312

13131313
// Set these attributes for the merged composite only (subimage 0)
1314-
composite_attribute("thumbnail_width", (int)width);
1315-
composite_attribute("thumbnail_height", (int)height);
1316-
composite_attribute("thumbnail_nchannels", 3);
1314+
composite_attribute("thumbnail_width", (int)m_thumbnail.spec().width);
1315+
composite_attribute("thumbnail_height", (int)m_thumbnail.spec().height);
1316+
composite_attribute("thumbnail_nchannels",
1317+
(int)m_thumbnail.spec().nchannels);
13171318
if (isBGR)
13181319
m_thumbnail = ImageBufAlgo::channels(m_thumbnail, 3, { 2, 1, 0 });
13191320
return true;

0 commit comments

Comments
 (0)