Double to float conversion is not always valid

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Double to float conversion is not always valid

Nicolas RUFF
Hello,

ASAN/UBSAN will flag the following operation in tif_dirread.c as a "float-cast-overflow" - which is true, a double cannot always fit into a float. I suggest the following fix:

case TIFF_DOUBLE:
{
  double m;
  err=TIFFReadDirEntryCheckedDouble(tif,direntry,&m);
  if (err!=TIFFReadDirEntryErrOk)
    return(err);
+ if ((m > FLT_MAX) || (m < FLT_MIN))
+   return(TIFFReadDirEntryErrRange);
  *value=(float)m;
  return(TIFFReadDirEntryErrOk);
}

WDYT?

Regards,
- Nicolas RUFF

_______________________________________________
Tiff mailing list: [hidden email]
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Double to float conversion is not always valid

Even Rouault-2

On mardi 27 juin 2017 15:16:28 CEST Nicolas RUFF wrote:

> Hello,

>

> ASAN/UBSAN will flag the following operation in tif_dirread.c as a

> "float-cast-overflow" - which is true, a double cannot always fit into a

> float. I suggest the following fix:

>

> case TIFF_DOUBLE:

> {

> double m;

> err=TIFFReadDirEntryCheckedDouble(tif,direntry,&m);

> if (err!=TIFFReadDirEntryErrOk)

> return(err);

> + if ((m > FLT_MAX) || (m < FLT_MIN))

> + return(TIFFReadDirEntryErrRange);

> *value=(float)m;

> return(TIFFReadDirEntryErrOk);

> }

>

> WDYT?

 

Committed. Thanks

 

>

> Regards,

> - Nicolas RUFF

 

 

--

Spatialys - Geospatial professional services

http://www.spatialys.com


_______________________________________________
Tiff mailing list: [hidden email]
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
Loading...