Opened 13 years ago

Last modified 13 years ago

#4097 closed defect

GDAL 1.8.0 cannot open an image file in Chinese. — at Initial Version

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

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.

Change History (2)

by davidhopper, 13 years ago

Attachment: GDALTest.2.zip added

by davidhopper, 13 years ago

Attachment: GDALTest.zip added
Note: See TracTickets for help on using tickets.