Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#5306 closed defect (fixed)

GDAL crashes when write jpeg2000 datasets without georeference

Reported by: drons Owned by: warmerdam
Priority: normal Milestone: 1.10.2
Component: GDAL_Raster Version: 1.10.1
Severity: normal Keywords:
Cc:

Description

This occurs in OpenJpeg driver when we write files with options GMLJP2=TRUE or GeoJP2=TRUE. We need add check result of CreateGMLJP2 & CreateJP2GeoTIFF in file openjpegdataset.cpp

openjpegdataset.cpp:1817: GDALJP2Box* poBox = oJP2MD.CreateGMLJP2(nXSize,nYSize);
openjpegdataset.cpp:1824: GDALJP2Box* poBox = oJP2MD.CreateJP2GeoTIFF();

Same problem in jpeg2000 driver. Need check at:

jpeg2000dataset.cpp:1200 GDALJP2Box *poBox = oJP2Geo.CreateJP2GeoTIFF();

Change History (5)

comment:1 by Even Rouault, 10 years ago

I tried the following with 1.10 branch and could not reproduce any crash :

gdal_translate data/gdalicon.png gdalicon.jp2 -of jp2openjpeg -b 1 -b 2 -b 3 -co resolutions=1 -co GMLJP2=TRUE -co GeoJP2=TRUE

gdal_translate data/gdalicon.png gdalicon.jp2 -of jpeg2000 -b 1 -b 2 -b 3 -co GMLJP2=TRUE -co GeoJP2=TRUE

In both cases, the drivers shouldn't even attempt to create the GMLJP2 or JP2GeoTIFF boxes if the file has no georeferencing, so I don't understand what can go wrong.

Could you attach a small image with which you reproduce the crash to this ticket, or at least put the output of the gdalinfo command on it ?

comment:2 by drons, 10 years ago

gdalinfo for my file:

sas@sas-ubuntu--12:~/Documents/prg/gdal-1.10.1/apps$ ./gdalinfo /mnt/hgfs/data/ALOS/ALPSMB242182825.tif 
Driver: GTiff/GeoTIFF
Files: /mnt/hgfs/data/ALOS/ALPSMB242182825.tif
Size is 16224, 14000
Coordinate System is `'
Metadata:
  TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)
  TIFFTAG_XRESOLUTION=50.799999
  TIFFTAG_YRESOLUTION=50.799999
Image Structure Metadata:
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0,14000.0)
Upper Right (16224.0,    0.0)
Lower Right (16224.0,14000.0)
Center      ( 8112.0, 7000.0)
Band 1 Block=128x128 Type=Byte, ColorInterp=Gray
  Overviews: 8112x7000, 4056x3500, 2028x1750, 1014x875, 507x437, 253x218

comment:3 by drons, 10 years ago

See please at GDAL source of openjpeg driver: openjpegdataset.cpp:1815 & openjpegdataset.cpp:1821. Functions GDALJP2Metadata::CreateGMLJP2 & GDALJP2Metadata::CreateJP2GeoTIFF can return NULL if source file have empty georeference, but OpenJPEGDataset::WriteBox don't check input for NULL value. Same function in ECW implementation of JPEG2000 do it.

comment:4 by Even Rouault, 10 years ago

Milestone: 1.10.2
Resolution: fixed
Status: newclosed

Was already fixed in trunk r26571, but residual dummy GeoJP2 box was written. Fixed in r26663

branches/1.10 r26664 "OpenJPEG: fix crash when translating a file that has TIFFTAG_RESOLUTION tags but no georeferencing (#5306), improve JP2OPENJPEG to be able to encode GCPs in a GeoJP2 box (#5279)"

I examined the JPEG2000 driver but the crash cannot occur since your source file has no georeferencing and code path that calls CreateJP2GeoTIFF() isn't taken.

The crash couldn't occur in JP2ECW since there's a protection against NULL boxes in GDALECWCompressor::WriteJP2Box(), but I've committed the following : trunk r26665, branches/1.10 r26666 "JP2ECW: avoid writing dummy GeoJP2 box when source dataset has no georeferencing (#5306)"

comment:5 by drons, 10 years ago

Thanks!

Note: See TracTickets for help on using tickets.