pcbnew, SVG import: fix an issue for SVG files using a CR+LF end of file

The issue was in a validity test working only if CR+LF is not replaced by LF
Fixes #10096
https://gitlab.com/kicad/code/kicad/issues/10096
This commit is contained in:
jean-pierre charras 2022-11-09 09:33:51 +01:00
parent 61d4a5bfbe
commit f136f3d7ee
2 changed files with 7 additions and 2 deletions

View File

@ -56,8 +56,11 @@ bool SVG_IMPORT_PLUGIN::Load( const wxString& aFileName )
{
wxCHECK( m_importer, false );
// wxFopen takes care of unicode filenames across platforms
FILE* fp = wxFopen( aFileName, wxT( "rt" ) );
// 1- wxFopen takes care of unicode filenames across platforms
// 2 - nanosvg (exactly nsvgParseFromFile) expects a binary file (exactly the CRLF eof must
// not be replaced by LF and changes the byte count) in one validity test,
// so open it in binary mode.
FILE* fp = wxFopen( aFileName, wxT( "rb" ) );
if( fp == nullptr )
return false;

View File

@ -3688,6 +3688,8 @@ NSVGimage* nsvgParseFromFile( FILE *fp, const char* units, float dpi )
if( data == NULL )
goto error;
// This test works only if fp is open in binary mode, i.e. if the CRLF eol is not
// replaced by LF when reading the file
if( fread( data, 1, size, fp ) != size )
goto error;