@@ -98,13 +98,9 @@ class CachedIO {
9898 bool getByte (uint8_t &res) {
9999 if (sz_ <= pos_) {
100100 sz_ = io_->read_proc (cache_, 1 , std::size (cache_), handle_);
101- #if 1
102101 if (sz_ < 1 ) {
103102 return false ;
104103 }
105- #else
106- sz_ = std::size(cache_);
107- #endif
108104 pos_ = 0 ;
109105 }
110106 res = cache_[pos_++];
@@ -251,7 +247,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
251247 uint8_t fillchar;
252248
253249 uint8_t *bits{}; // Pointer to dib data
254- uint32_t x, y;
250+ uint16_t x, y;
255251
256252 if (!handle) {
257253 return nullptr ;
@@ -282,9 +278,9 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
282278 if (header.magic != RAS_MAGIC) {
283279 throw FI_MSG_ERROR_MAGIC_NUMBER;
284280 }
285- /* if (header.width > 65500 || header.height > 65500) {
281+ if (header.width > 65500 || header.height > 65500 ) {
286282 throw FI_MSG_ERROR_DIB_MEMORY;
287- }*/
283+ }
288284
289285 // Allocate a new DIB
290286 std::unique_ptr<FIBITMAP, decltype (&FreeImage_Unload)> dib (nullptr , &FreeImage_Unload);
@@ -304,9 +300,6 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
304300 throw FI_MSG_ERROR_DIB_MEMORY;
305301 }
306302
307- header.width = FreeImage_GetWidth (dib.get ());
308- header.height = FreeImage_GetHeight (dib.get ());
309-
310303 // Check the file format
311304
312305 switch (header.type ) {
@@ -357,7 +350,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
357350 // Read SUN raster colormap
358351
359352 int numcolors = 1 << header.depth ;
360- if ((uint32_t )(3 * numcolors) > header.maplength ) {
353+ if ((uint32_t )(3 * numcolors) >= header.maplength ) {
361354 // some RAS may have less colors than the full palette
362355 numcolors = header.maplength / 3 ;
363356 } else {
@@ -408,7 +401,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
408401 linelength = (uint16_t )header.width ;
409402 }
410403
411- fill = ( linelength & 1 ) ? 1 : 0 ;
404+ fill = linelength & 1 ;
412405
413406 // Read the image data
414407
0 commit comments