locationtech / locationtech/geotrellis

GDALRasterSource will read corrupt jp2 successfully

Open
#3,547 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Scala
Stars
1.4k
Forks
360
Avg merge
6h 57m
Merged PRs (30d)
12

Description

Describe the bug

I can create a GDALRasterSource from a corrupt JPEG2000 file and successfully read from it. I would expect it to throw an exception instead of silently proceeding with wrong data.

To Reproduce

import geotrellis.raster.gdal.GDALRasterSource
import geotrellis.raster.io.geotiff.MultibandGeoTiff

val rs = GDALRasterSource("https://artifactory.vgt.vito.be/artifactory/testdata-public/T29UMV_20180327T114351_B04_10m.jp2")
val Some(raster) = rs.read()
MultibandGeoTiff(raster, rs.crs).write("/tmp/rasterSourceFromCorruptTile.tif")

This will successfully read a corrupt JPEG2000 file and write it to a GeoTiff that looks funky. GDAL will output erorr messages along the way look like this:

[1 of 1000] FAILURE(3) CPLE_AppDefined(1) "Application defined error." Inconsistent marker size
[2 of 1000] FAILURE(3) CPLE_AppDefined(1) "Application defined error." opj_get_decoded_tile() failed 

Expected behavior

I would expect it to throw an exception instead of silently proceeding with wrong data. gdalinfo for example, will output error messages instead:

$ gdalinfo -stats https://artifactory.vgt.vito.be/artifactory/testdata-public/T29UMV_20180327T114351_B04_10m.jp2
...
ERROR 1: Stream too short, expected SOT

ERROR 1: opj_get_decoded_tile() failed
ERROR 1: /vsimem/http_1/T29UMV_20180327T114351_B04_10m.jp2, band 1: IReadBlock failed at X offset 5, Y offset 8: opj_get_decoded_tile() failed

Environment

  • Java version: 11
  • Scala version: 2.12.18
  • GeoTrellis version: 3.6.0
  • gdal-warp-bindings version: 3.8.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the GDALRasterSource construction and read path, reproducing the provided URL case with the listed GDAL error output. Trace how errors from GDAL are handled during raster reads. Done means the corrupt JPEG2000 input raises an exception instead of returning silently incorrect raster data, with regression coverage for the reported behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.