Opened 13 years ago

Closed 13 years ago

#4097 closed defect (invalid)

GDAL 1.8.0 cannot open an image file in Chinese.

Reported by: davidhopper Owned by: warmerdam
Priority: highest Milestone:
Component: default Version: 1.8.0
Severity: normal Keywords: GDAL 1.8.0, Chinese
Cc:

Description (last modified by davidhopper)

Dear Sir,

I have been using the GDAL library for several years. As far as I know, it is really the best translator library for raster geospatial data formats. It is very lucky for me to have such an excellent product. I really admire your contributive work. But I have encountered a serious bug in the GDAL 1.8.0 version when I tried to open an image file in Chinese. The problem is described as follows. The test program can be found in the attached files. Please give me some advice. Thank you very much. By the way, I think it would be better that if you provide an overloading edition accepting a UNICODE filename for the function of "GDALOpen()". After all, internationalization is so popular that a filename cannot be presented only with ANSI character set. As is well known, Windows 2000 and later version operating system treat all of the texts as UNICODE characters natively. Thus, it would be more efficient if we use UNICODE characters handle filenames.

Yours Sincerely,

David Hopper (He Zhiguo)

Bug description:

  1. In GDALTest.cpp main():

poDataset = (GDALDataset *) GDALOpen( pszFilename, GA_ReadOnly );

  1. In gcore/gdaldataset.cpp GDALOpen():

return GDALOpenInternal(pszFilename, eAccess, NULL);

  1. In gcore/gdaldataset.cpp GDALOpenInternal():

GDALOpenInfo oOpenInfo( pszFilename, eAccess );

  1. In gcore/gdalopeninfo.cpp GDALOpenInfo::GDALOpenInfo():

if( VSIStatExL( pszFilename, &sStat,

VSI_STAT_EXISTS_FLAG | VSI_STAT_NATURE_FLAG ) == 0 )

  1. In port/cpl_vsil.cpp VSIStatExL():

return poFSHandler->Stat( pszFilename, psStatBuf, nFlags );

  1. in port/cpl_vsil_win32.cpp VSIWin32FilesystemHandler::Stat():
#if (defined(WIN32) && _MSC_VER >= 1310)
MSVCRT_VERSION >= 0x0601

if( CSLTestBoolean(

CPLGetConfigOption( "GDAL_FILENAME_IS_UTF8", "YES" ) ) )

{

int nResult; wchar_t *pwszFilename =

CPLRecodeToWChar( pszFilename, CPL_ENC_UTF8, CPL_ENC_UCS2 );

nResult = _wstat64( pwszFilename, pStatBuf ); CPLFree( pwszFilename ); return nResult;

} else

#endif

The CPLRecodeToWChar () function failed to convert a Chinese filename with multibyte character set to one with UNICODE character set. The following is the description of the CPLRecodeToWChar () function:

Convert a 8bit, multi-byte per character input string into a wide character (wchar_t) string. The only guaranteed supported source encodings are CPL_ENC_UTF8, CPL_ENC_ASCII and CPL_ENC_ISO8869_1 (LATIN1). The only guaranteed supported destination encoding is CPL_ENC_UCS2. Other source and destination encodings may be supported depending on the underlying implementation.

Attachments (2)

GDALTest.2.zip (433.0 KB ) - added by davidhopper 13 years ago.
GDALTest.zip (433.0 KB ) - added by davidhopper 13 years ago.

Download all attachments as: .zip

Change History (6)

by davidhopper, 13 years ago

Attachment: GDALTest.2.zip added

by davidhopper, 13 years ago

Attachment: GDALTest.zip added

comment:1 by davidhopper, 13 years ago

Description: modified (diff)

comment:2 by Even Rouault, 13 years ago

Are the encoding of your cpp test file and the filename passed to GDAL UTF-8 ? If not, that will explain the error because now GDALOpen() expects filenames to be passed as UTF-8 strings.

comment:3 by davidhopper, 13 years ago

Version: unspecified1.8.0

comment:4 by Even Rouault, 13 years ago

Resolution: invalid
Status: newclosed

Yes, I've checked that your cpp test file and the filename string in it are in one of the GB encodings, not UTF-8. So not a bug

Note: See TracTickets for help on using tickets.