Skip to content

Commit

Permalink
Merge pull request OSGeo#10796 from kevinmehall/jpeg-warning
Browse files Browse the repository at this point in the history
JPEG: Fix inverted handling of GDAL_ERROR_ON_LIBJPEG_WARNING
  • Loading branch information
rouault authored Sep 13, 2024
2 parents daab6da + 29b0bad commit 78a1e2b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
Binary file added autotest/gdrivers/data/jpeg/byte_corrupted3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 31 additions & 3 deletions autotest/gdrivers/jpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ def test_jpeg_17():

assert not (
gdal.GetLastErrorType() != gdal.CE_Failure or gdal.GetLastErrorMsg() == ""
)
), "Premature end of file should be a failure by default"

gdal.ErrorReset()
ds = gdal.Open("data/jpeg/byte_corrupted2.jpg")
Expand All @@ -603,7 +603,7 @@ def test_jpeg_17():

assert not (
gdal.GetLastErrorType() != gdal.CE_Failure or gdal.GetLastErrorMsg() == ""
)
), "Premature end of file should be a failure with GDAL_ERROR_ON_LIBJPEG_WARNING = TRUE"

gdal.ErrorReset()
ds = gdal.Open("data/jpeg/byte_corrupted2.jpg")
Expand All @@ -613,7 +613,35 @@ def test_jpeg_17():

assert not (
gdal.GetLastErrorType() != gdal.CE_Warning or gdal.GetLastErrorMsg() == ""
)
), "Premature end of file should be a warning with GDAL_ERROR_ON_LIBJPEG_WARNING = FALSE"

gdal.ErrorReset()
with gdaltest.error_handler("CPLQuietErrorHandler"):
ds = gdal.Open("data/jpeg/byte_corrupted3.jpg")
assert ds.GetRasterBand(1).Checksum() != 0

assert not (
gdal.GetLastErrorType() != gdal.CE_Warning or gdal.GetLastErrorMsg() == ""
), "Extraneous bytes before marker should be a warning by default"

gdal.ErrorReset()
with gdaltest.error_handler("CPLQuietErrorHandler"):
with gdaltest.config_option("GDAL_ERROR_ON_LIBJPEG_WARNING", "TRUE"):
ds = gdal.Open("data/jpeg/byte_corrupted3.jpg")

assert not (
gdal.GetLastErrorType() != gdal.CE_Failure or gdal.GetLastErrorMsg() == ""
), "Extraneous bytes before marker should be a failure with GDAL_ERROR_ON_LIBJPEG_WARNING = TRUE"

gdal.ErrorReset()
with gdaltest.error_handler("CPLQuietErrorHandler"):
with gdaltest.config_option("GDAL_ERROR_ON_LIBJPEG_WARNING", "FALSE"):
ds = gdal.Open("data/jpeg/byte_corrupted3.jpg")
assert ds.GetRasterBand(1).Checksum() != 0

assert not (
gdal.GetLastErrorType() != gdal.CE_Warning or gdal.GetLastErrorMsg() == ""
), "Extraneous bytes before marker should be a warning with GDAL_ERROR_ON_LIBJPEG_WARNING = FALSE"


###############################################################################
Expand Down
2 changes: 1 addition & 1 deletion frmts/jpeg/jpgdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3744,7 +3744,7 @@ void JPGDataset::EmitMessage(j_common_ptr cinfo, int msg_level)
buffer);
}
}
else if (pszVal == nullptr || CPLTestBool(pszVal))
else if (pszVal == nullptr || !CPLTestBool(pszVal))
{
if (pszVal == nullptr)
{
Expand Down

0 comments on commit 78a1e2b

Please sign in to comment.