Skip to content

Commit

Permalink
fix(psd): Prevent simultaneous psd thumbnail reads from clashing (Aca…
Browse files Browse the repository at this point in the history
…demySoftwareFoundation#3877)

When reading a PSD file, if it contains a thumbnail, we read it from the
in-memory blob with a combination of an IOMemReader and an ImageBuf.
But... we always named it "thumbnail.jpg" without considering that
multiple simultaneous PSD files reading identically named images (but
which are in fact different) could cause a weird kind of clashing in any
underlying use of ImageCache!

The simple fix is to use ordinary ImageInput approach to reading the
thumbnail from the IOMemReader, but just store it in the ImageBuf.

Fixes AcademySoftwareFoundation#3824

Signed-off-by: Larry Gritz <lg@larrygritz.com>
  • Loading branch information
lgritz committed Jun 12, 2023
1 parent 749a557 commit 8add832
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/psd.imageio/psdinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1322,9 +1322,27 @@ PSDInput::load_resource_thumbnail(uint32_t length, bool isBGR)
if (!ioread(&jpeg_data[0], jpeg_length))
return false;

// Create an IOMemReader that references the thumbnail JPEG blob and read
// it with an ImageInput, into the memory owned by an ImageBuf.
Filesystem::IOMemReader thumbblob(jpeg_data.data(), jpeg_length);
m_thumbnail = ImageBuf("thumbnail.jpg", 0, 0, nullptr, nullptr, &thumbblob);
m_thumbnail.read(0, 0, true);
m_thumbnail.clear();
auto imgin = ImageInput::open("thumbnail.jpg", nullptr, &thumbblob);
if (imgin) {
ImageSpec spec = imgin->spec(0);
m_thumbnail.reset(spec, InitializePixels::No);
ok = imgin->read_image(0, 0, 0, m_thumbnail.spec().nchannels,
m_thumbnail.spec().format,
m_thumbnail.localpixels());
imgin.reset();
} else {
errorfmt("Failed to open thumbnail");
return false;
}
if (!ok) {
errorfmt("Failed to read thumbnail: {}", m_thumbnail.geterror());
m_thumbnail.clear();
return false;
}

// Set these attributes for the merged composite only (subimage 0)
composite_attribute("thumbnail_width", (int)m_thumbnail.spec().width);
Expand Down

0 comments on commit 8add832

Please sign in to comment.