From 2becd368d91d27da74c08093b35b716a326bf674 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Sun, 20 Sep 2020 22:39:31 +0100 Subject: [PATCH] Thirdparty: Properly handle error condition in nanosvg ftell() returns -1 on an error, so it must be a long return type, and we should test for its failure. (found by Coverity) --- thirdparty/nanosvg/nanosvg.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/thirdparty/nanosvg/nanosvg.cpp b/thirdparty/nanosvg/nanosvg.cpp index 607b6b8120..b6f3ca559b 100644 --- a/thirdparty/nanosvg/nanosvg.cpp +++ b/thirdparty/nanosvg/nanosvg.cpp @@ -3669,7 +3669,7 @@ NSVGimage* nsvgParse( char* input, const char* units, float dpi ) NSVGimage* nsvgParseFromFile( FILE *fp, const char* units, float dpi ) { - size_t size; + long size; char* data = NULL; NSVGimage* image = NULL; @@ -3678,6 +3678,10 @@ NSVGimage* nsvgParseFromFile( FILE *fp, const char* units, float dpi ) fseek( fp, 0, SEEK_END ); size = ftell( fp ); + + if( size < 0 ) + goto error; + fseek( fp, 0, SEEK_SET ); data = (char*) malloc( size + 1 );