Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JPEG: Fix inverted handling of GDAL_ERROR_ON_LIBJPEG_WARNING #10796

Merged
merged 1 commit into from
Sep 13, 2024

Conversation

kevinmehall
Copy link
Contributor

What does this PR do?

Since #7016, the behavior of the GDAL_ERROR_ON_LIBJPEG_WARNING option is inverted, producing errors when FALSE and warnings when TRUE for the types of problems that are warnings by default. For example:

$ gdal_translate byte_corrupted3.jpg out.png
Warning 1: libjpeg: Corrupt JPEG data: 20 extraneous bytes before marker 0xda (this warning
can be turned as an error by setting GDAL_ERROR_ON_LIBJPEG_WARNING to TRUE)
Input file size is 24, 24
0...10...20...30...40...50...60...70...80...90...100 - done.

$ GDAL_ERROR_ON_LIBJPEG_WARNING=TRUE gdal_translate byte_corrupted3.jpg out.png
Warning 1: libjpeg: Corrupt JPEG data: 20 extraneous bytes before marker 0xda
Input file size is 24, 24
0...10...20...30...40...50...60...70...80...90...100 - done.

$ GDAL_ERROR_ON_LIBJPEG_WARNING=FALSE gdal_translate byte_corrupted3.jpg out.png
ERROR 1: libjpeg: Corrupt JPEG data: 20 extraneous bytes before marker 0xda
Input file size is 24, 24
ERROR 1: byte_corrupted3.jpg, band 1: IReadBlock failed at X offset 0, Y offset 0
ERROR 1: libpng: No IDATs written into file

The byte_corrupted3.jpg file was generated with:

from osgeo import gdal

src_ds = gdal.GetDriverByName("Mem").Create("", 24, 24)
src_ds.GetRasterBand(1).Fill(0xff)
ds = gdal.GetDriverByName("JPEG").CreateCopy("/vsimem/x.jpg", src_ds)
vsifile = gdal.VSIFOpenL("/vsimem/x.jpg", 'r')
b = list(gdal.VSIFReadL(1, 1024, vsifile))

b[0x93:0x93] = [0] * 20

open('autotest/gdrivers/data/jpeg/byte_corrupted3.jpg', 'wb').write(bytes(b))

Tasklist

  • Make sure code is correctly formatted (cf pre-commit configuration)
  • Add test case(s)
  • Add documentation
  • Updated Python API documentation (swig/include/python/docs/)
  • Review
  • Adjust for comments
  • All CI builds and checks have passed

@coveralls
Copy link
Collaborator

Coverage Status

coverage: 69.362%. remained the same
when pulling 29b0bad on kevinmehall:jpeg-warning
into acca3c2 on OSGeo:master.

@rouault
Copy link
Member

rouault commented Sep 13, 2024

Thanks!

@rouault rouault merged commit 78a1e2b into OSGeo:master Sep 13, 2024
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants