Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/psd.imageio/psdinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1013,25 +1013,36 @@ PSDInput::validate_header()
errorfmt("[Header] invalid depth {}", m_header.depth);
return false;
}
if (m_WantRaw)
return true;

//There are other (undocumented) color modes not listed here
// Reject any color mode outside the known set before the RawColor early
// return below: setup() indexes mode_channel_count/mode_channel_names by
// m_header.color_mode unconditionally (even for raw reads), so an
// out-of-table value (or one of the undocumented gaps, e.g. 5 and 6)
// must never reach that point regardless of m_WantRaw.
switch (m_header.color_mode) {
case ColorMode_Bitmap:
case ColorMode_Indexed:
case ColorMode_RGB:
case ColorMode_Grayscale:
case ColorMode_CMYK:
case ColorMode_Multichannel: break;
case ColorMode_Multichannel:
case ColorMode_Duotone:
case ColorMode_Lab:
errorfmt("[Header] unsupported color mode {:d}", m_header.color_mode);
return false;
case ColorMode_Lab: break;
default:
errorfmt("[Header] unrecognized color mode {:d}", m_header.color_mode);
return false;
}

if (m_WantRaw)
return true;

// Duotone and Lab are only supported via the raw path (handled above).
switch (m_header.color_mode) {
case ColorMode_Duotone:
case ColorMode_Lab:
errorfmt("[Header] unsupported color mode {:d}", m_header.color_mode);
return false;
default: break;
}
return true;
}

Expand Down
4 changes: 4 additions & 0 deletions testsuite/psd-colormodes/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ indexed-transparency-0.psd : 200 x 150, 4 channel, uint8 psd
indexed-transparency-255.psd : 200 x 150, 4 channel, uint8 psd
SHA-1: BEF32B02F44B369E39670DC2E2D2D1578B4998AD
indexed-transparency-256-rejected
oiiotool ERROR: read : [Header] unrecognized color mode 20
failed to open "src/bad_colormode.psd": failed load_header
Full command line was:
> oiiotool --nostderr --info --iconfig oiio:RawColor 1 src/bad_colormode.psd
Comparing "pattern2-8-rgb.psd.tif" and "ref/pattern2.tif"
PASS
Comparing "pattern2-16-rgb.psd.tif" and "ref/pattern2.tif"
Expand Down
3 changes: 3 additions & 0 deletions testsuite/psd-colormodes/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@
+ "out.null > /dev/null 2>&1 "
+ "|| echo indexed-transparency-256-rejected)")

# Regression test: bad colormode
command += oiiotool ("--nostderr --info --iconfig oiio:RawColor 1 src/bad_colormode.psd", failureok=True)

outputs += [ "out.txt" ]
Binary file added testsuite/psd-colormodes/src/bad_colormode.psd
Binary file not shown.
Loading