Improve handling oof corrupted PNG images (resolves openfl/openfl#1999)

This commit is contained in:
Joshua Granick
2018-10-10 14:57:27 -07:00
parent 080666c95b
commit a5bef44d65
2 changed files with 32 additions and 9 deletions

View File

@@ -21,9 +21,9 @@ namespace lime {
ReadBuffer (const unsigned char* data, int length) : data (data), length (length), position (0) {}
void Read (unsigned char* out, int count) {
bool Read (unsigned char* out, int count) {
if (position >= length) return;
if (position >= length) return false;
if (count > length - position) {
@@ -37,6 +37,8 @@ namespace lime {
}
return true;
}
char unused; // the first byte gets corrupted when passed to libpng?
@@ -57,7 +59,9 @@ namespace lime {
static void user_read_data_fn (png_structp png_ptr, png_bytep data, png_size_t length) {
ReadBuffer* buffer = (ReadBuffer*)png_get_io_ptr (png_ptr);
buffer->Read (data, length);
if (!buffer->Read (data, length)) {
png_error (png_ptr, "Read Error");
}
}