Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#2786 closed defect (fixed)

TIFF SetMetadata corrupts XML string

Reported by: gaopeng Owned by: warmerdam
Priority: normal Milestone: 1.5.4
Component: GDAL_Raster Version: 1.6.0
Severity: normal Keywords: GTiff


Attached are two files containing what was written to TIFF using SetMetadata, and the metadata read back from the tiff. The returned metadata in the metadata domain, <Metadata domain="xml:ESRI" format="xml">, is no longer a valid XML string.

It's not clear when the XML is changed, before it's written to TIFF, or before it's returned from tiff driver.

Attachments (3)

palmsprings_1tif_good_xml.xml (3.2 KB ) - added by gaopeng 14 years ago.
palmsprings_1tif_bad_xml.xml (2.3 KB ) - added by gaopeng 14 years ago.
palmsprings_1tif.tif (817.2 KB ) - added by gaopeng 14 years ago.

Download all attachments as: .zip

Change History (8)

by gaopeng, 14 years ago

by gaopeng, 14 years ago

by gaopeng, 14 years ago

Attachment: palmsprings_1tif.tif added

comment:1 by warmerdam, 14 years ago

Component: defaultGDAL_Raster
Keywords: GTiff added; Raster removed
Owner: changed from Frank Warmerdam to warmerdam
Status: newassigned


The TIFF file is rather badly corrupted in the metadata tag. I have been unable to reproduce a similar problem writing out metadata. I used the following script with trunk, 1.5, and 1.4 branches. Can you indicate what version the file was generated with?

import gdal

good_xml = """   <GeodataXform xsi:type="typens:PolynomialXform" xmlns:xsi="" xmlns:xs="" xmlns:typens="">

ds = gdal.Open('wrk.tif',gdal.GA_Update)

md = {}
md['GeodataXform'] = good_xml

ds.SetMetadata( md, 'xml:ESRI' )

ds = None

comment:2 by gaopeng, 14 years ago


I am using GDAL 1.6.0. However I did have a minor local fix, which added ! in front of EQUAL. Otherwise the metadata are not saved.

CPLErr GTiffDataset::SetMetadata( char papszMD, const char *pszDomain )


if( pszDomain == NULL
!EQUAL(pszDomain,"_temporary_") )

bMetadataChanged = TRUE;

return oGTiffMDMD.SetMetadata( papszMD, pszDomain );


comment:3 by warmerdam, 14 years ago

I have confirmed the original bug, using the following mechanism:

#include "gdal_priv.h"

int main()

    char *apszMD[2] = {
        "<GeodataXform xsi:type=\"typens:PolynomialXform\" xmlns:xsi=\"\" xmlns:xs=\"\" xmlns:typens=\"\">      <PolynomialOrder>2</PolynomialOrder>    </GeodataXform>",
        NULL };


    GDALDataset *poDS = (GDALDataset *) GDALOpen("wrk.tif",GA_Update);

    poDS->SetMetadata( apszMD, "xml:ESRI" );
    GDALClose( (GDALDatasetH) poDS );

The problem seems to be missing support for the special xml: domain prefix in the GeoTIFF driver. There are also issues with the geotiff driver's _temporary_ tests which I will fix.

comment:4 by warmerdam, 14 years ago

Resolution: fixed
Status: assignedclosed

I have corrected the GeoTIFF driver to support the special handling of xml: domain metadata in trunk (r16147) and 1.6 branch (r16148). I have also added testing for this in autotest (r16150).

Unfortunately, the xml metadata in any previously produced files will be corrupt.

I have also ported a small variation on this into 1.5 branch (r16161).

comment:5 by gaopeng, 14 years ago

I have confirmed that the fix solved the problem.

Note: See TracTickets for help on using tickets.