Skip to content

Commit

Permalink
TIFF: Fix spec() and spec_dimensions() for mipmapped tiff files (Acad…
Browse files Browse the repository at this point in the history
…emySoftwareFoundation#2723)

For "mip-mapped" TIFF files where we use the multiple images in the file
to emulate MIP-maps rather than what we ordinarily consider subimages,
a call to `ImageInput::spec(subimage,miplevel)` was not properly
recognizing invalid subimage values and returning an empty ImageSpec
as advertised. Basically, we assumed that they would only ask for a
valid subimage and miplevel and didn't properly handle out of range
values.

Same problem for spec_dimensions().

Signed-off-by: Larry Gritz <lg@larrygritz.com>
  • Loading branch information
lgritz committed Sep 26, 2020
1 parent 8af1d39 commit 496777a
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/tiff.imageio/tiffinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,20 @@ ImageSpec
TIFFInput::spec(int subimage, int miplevel)
{
ImageSpec ret;
int s = m_emulate_mipmap ? miplevel : subimage;

// s == index of the spec list to retrieve. Start by presuming it's
// the sublevel number.
int s = subimage;
if (m_emulate_mipmap) {
// This is the kind of TIFF file where we are emulating MIPmap
// levels with TIFF subimages.
if (subimage != 0)
return ret; // Invalid subimage request, return the empty spec
// Index into the spec list by miplevel instead, because that's
// what it really contains.
s = miplevel;
}

lock_guard lock(m_mutex);
if (s >= 0 && s < int(m_subimage_specs.size())
&& !m_subimage_specs[s].undefined()) {
Expand All @@ -747,7 +760,20 @@ ImageSpec
TIFFInput::spec_dimensions(int subimage, int miplevel)
{
ImageSpec ret;
int s = m_emulate_mipmap ? miplevel : subimage;

// s == index of the spec list to retrieve. Start by presuming it's
// the sublevel number.
int s = subimage;
if (m_emulate_mipmap) {
// This is the kind of TIFF file where we are emulating MIPmap
// levels with TIFF subimages.
if (subimage != 0)
return ret; // Invalid subimage request, return the empty spec
// Index into the spec list by miplevel instead, because that's
// what it really contains.
s = miplevel;
}

lock_guard lock(m_mutex);
if (s >= 0 && s < int(m_subimage_specs.size())
&& !m_subimage_specs[s].undefined()) {
Expand Down

0 comments on commit 496777a

Please sign in to comment.