Merge pull request #8343 from radarhere/jpeg2000_colorspace

This commit is contained in:
Hugo van Kemenade 2024-09-03 09:49:13 +03:00 committed by GitHub
commit d636b804d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 3 deletions

View File

@ -182,6 +182,15 @@ def test_restricted_icc_profile() -> None:
ImageFile.LOAD_TRUNCATED_IMAGES = False ImageFile.LOAD_TRUNCATED_IMAGES = False
@pytest.mark.skipif(
not os.path.exists(EXTRA_DIR), reason="Extra image files not installed"
)
def test_unknown_colorspace() -> None:
with Image.open(f"{EXTRA_DIR}/file8.jp2") as im:
im.load()
assert im.mode == "L"
def test_header_errors() -> None: def test_header_errors() -> None:
for path in ( for path in (
"Tests/images/invalid_header_length.jp2", "Tests/images/invalid_header_length.jp2",

View File

@ -698,8 +698,7 @@ j2k_decode_entry(Imaging im, ImagingCodecState state) {
} }
/* Check that this image is something we can handle */ /* Check that this image is something we can handle */
if (image->numcomps < 1 || image->numcomps > 4 || if (image->numcomps < 1 || image->numcomps > 4) {
image->color_space == OPJ_CLRSPC_UNKNOWN) {
state->errcode = IMAGING_CODEC_BROKEN; state->errcode = IMAGING_CODEC_BROKEN;
state->state = J2K_STATE_FAILED; state->state = J2K_STATE_FAILED;
goto quick_exit; goto quick_exit;
@ -744,7 +743,7 @@ j2k_decode_entry(Imaging im, ImagingCodecState state) {
/* Find the correct unpacker */ /* Find the correct unpacker */
color_space = image->color_space; color_space = image->color_space;
if (color_space == OPJ_CLRSPC_UNSPECIFIED) { if (color_space == OPJ_CLRSPC_UNKNOWN || color_space == OPJ_CLRSPC_UNSPECIFIED) {
switch (image->numcomps) { switch (image->numcomps) {
case 1: case 1:
case 2: case 2: