Skip to content

GDAL mistakes one of the ENVI correction rasters for a JPEG and fails #206

Closed
@scottstanie

Description

@scottstanie

@taliboliver found a very sneaky bug:
Reproduce with:

s1_cslc.py /home/staniewi/repos/COMPASS/talib-error/geo_runconfig_20230518_t042_088919_iw3.yaml
Warning 1: libjpeg: Corrupt JPEG data: 405 extraneous bytes before marker 0x6e (this warning can be turned as an error by setting GDAL_ERROR_ON_LIBJPEG_WARNING to TRUE)
Traceback (most recent call last):
  File "/u/aurora-r0/staniewi/miniconda3/envs/mapping-311/bin/s1_cslc.py", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/u/aurora-r0/staniewi/repos/COMPASS/src/compass/s1_cslc.py", line 53, in main
    run(parser.run_config_path, parser.args.grid_type)
  File "/u/aurora-r0/staniewi/repos/COMPASS/src/compass/s1_cslc.py", line 45, in run
    s1_geocode_slc.run(cfg)
  File "/u/aurora-r0/staniewi/repos/COMPASS/src/compass/s1_geocode_slc.py", line 92, in run
    cumulative_correction_luts(burst, dem_path=cfg.dem,
  File "/u/aurora-r0/staniewi/repos/COMPASS/src/compass/utils/lut.py", line 63, in cumulative_correction_luts
    compute_geocoding_correction_luts(burst,
  File "/u/aurora-r0/staniewi/repos/COMPASS/src/compass/utils/lut.py", line 212, in compute_geocoding_correction_luts
    [open_raster(raster_path) for raster_path in rdr2geo_raster_paths]
  File "/u/aurora-r0/staniewi/repos/COMPASS/src/compass/utils/lut.py", line 212, in <listcomp>
    [open_raster(raster_path) for raster_path in rdr2geo_raster_paths]
     ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/u/aurora-r0/staniewi/repos/COMPASS/src/compass/utils/helpers.py", line 351, in open_raster
    ds = gdal.Open(filename, gdal.GA_ReadOnly)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/u/aurora-r0/staniewi/miniconda3/envs/mapping-311/lib/python3.11/site-packages/osgeo/gdal.py", line 5297, in Open
    return _gdal.Open(*args)
           ^^^^^^^^^^^^^^^^^
RuntimeError: libjpeg: Unsupported marker type 0x6e

Apparently the x.rdr raster inside the corrections folder is getting misread by GDAL. I've seen a similar problem with other binary drivers here OSGeo/gdal#4713 , but I think GDAL uses a heuristic to guess the driver, and if the contents of the file match the heuristic, it can guess wrong.

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions