[cairo] [PATCH] Generate better error message when loading invalid PNGs

Bill Spitzak spitzak at gmail.com
Sat Mar 26 02:35:46 UTC 2016


On 03/25/2016 01:24 PM, Cyril Roelandt wrote:
> On 03/25/2016 08:24 PM, Bill Spitzak wrote:
>> I really don't see this as better, because now you are relying on local
>> code arriving at exactly the same "is this a png file" conclusion as
>> libpng. Also there are lots of other errors that are not no-memory.
>>
>> Grepping libpng for png_error, I think perhaps this code will pick the most
>> appropriate error:
>>
>>      if (strstr(message, "alloc") || strstr(message, "OOM") ||
>> strstr(message, "memory")
>>           return CAIRO_STATUS_NO_MEMORY;
>>      else
>>           return CAIRO_STATUS_READ_ERROR;
>>
>
> Why wouldn't we grep for "Not a PNG" as well? Also, Uli stated that it
> might not be the best idea to rely on the error messages from libpng,
> since they might change. WDYT?
>
> Using png_sig_cmp allow us to be perfectly sure that the issue is with
> the file/stream, and to return an appropriate error code to the user,
> without gambling.

Because looking at the source code I can see a lot more errors that are 
not "out of memory" but they would be tagged this way. To me it looks 
easier to detect the out of memory errors because they use some words in 
common.




More information about the cairo mailing list