Opened 10 years ago

Last modified 10 years ago

#5467 closed defect

ENVI driver .hdr corruption — at Initial Version

Reported by: wilsonwaters Owned by: Even Rouault
Priority: normal Milestone: 1.11.1
Component: GDAL_Raster Version: 1.11.0
Severity: major Keywords: envi, hdr
Cc: antonio

Description

We found our ENVI .hdr files were being corrupted whenever opened in write mode with GDAL. No changes to the data or metadata are required to corrupt the file, simply opening the file in write mode was enough. I've attached example before and after .hdr files. These files have map info projection set to "Arbitrary" (we're not storing map data. It's long skinny images of underground drill core).

This is the process causing the corruption in ENVIDataset: 1) open envi file in read/write mode uses OPEN_EXISTING flag on .hdr 2) ENVIDataset::Open() doesn't understand "Arbitrary" projection so generates a "LOCAL_CS" projection string 3) close dataset causing ENVIDataset::FlushCache() to be called 4) FlushCache() re-writes hdr file as the bHeaderDirty was set in the Open() function. map info field is omitted for some reason? 5) FlushCache() overwrites the old hdr file without clearing first causing trailing data in the file

As far as I can tell there are four bugs in the ENVIDataset related to this 1) ENVIDataset::ProcessMapinfo() Doesn't understand the "Arbitrary" projection and defaults to LOCAL_CS - which is probably ok, but; 2) ENVIDataset::WriteProjectionInfo fails to write map info field when projection is LOCAL_CS 3) ENVIDataset::Open() causes bHeaderDirty to be set (should only happen when something external updates the image?) 4) ENVIDataset::FlushCache() should truncate existing file before overwriting

We're using GDAL 1.11 on windows, though I think the behaviour would be the same on any OS.

Change History (3)

by wilsonwaters, 10 years ago

Attachment: envidataset.cpp.diff added

patch for envidataset.cpp

by wilsonwaters, 10 years ago

Attachment: good.hdr added

example of an original, un-corrupted hdr file

by wilsonwaters, 10 years ago

Attachment: bad.hdr added

example of a bad, corrupted hdr file

Note: See TracTickets for help on using tickets.