php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79336 ext/exif/tests/bug79046.phpt fails on Big endian arch
Submitted: 2020-03-03 10:40 UTC Modified: 2020-03-03 10:45 UTC
From: vibhutisawant18 at gmail dot com Assigned:
Status: Closed Package: EXIF related
PHP Version: master-Git-2020-03-03 (Git) OS: Ubuntu 16.04
Private report: No CVE-ID: None
 [2020-03-03 10:40 UTC] vibhutisawant18 at gmail dot com
Description:
------------
NaN to int cast undefined behavior in exif [ext/exif/tests/bug79046.phpt]
Above TC fails on big endian architecture, the expected value for StripOffsets is NAN whereas that returned on Big endian is float(8.9143601808023E-41)

Could you please guide us on how to go about it.

PFA test case logs on Little and Big endian Architecture.

Little Endian:

test@a2a9ec71b826:~/php/php-src$ ./sapi/cli/php  -f "ext/exif/tests/bug79046.phpt"
--TEST--
Bug #79046: NaN to int cast undefined behavior in exif
--FILE--

array(8) {
  ["FileDateTime"]=>
  int(0)
  ["FileSize"]=>
  int(33)
  ["FileType"]=>
  int(8)
  ["MimeType"]=>
  string(10) "image/tiff"
  ["SectionsFound"]=>
  string(24) "ANY_TAG, IFD0, THUMBNAIL"
  ["COMPUTED"]=>
  array(2) {
    ["IsColor"]=>
    int(0)
    ["ByteOrderMotorola"]=>
    int(1)
  }
  ["StripOffsets"]=>
  float(NAN)
  ["THUMBNAIL"]=>
  array(1) {
    ["StripOffsets"]=>
    float(NAN)
  }
}

Big endian:

--TEST--
Bug #79046: NaN to int cast undefined behavior in exif
--FILE--
array(8) {
  ["FileDateTime"]=>
  int(0)
  ["FileSize"]=>
  int(33)
  ["FileType"]=>
  int(8)
  ["MimeType"]=>
  string(10) "image/tiff"
  ["SectionsFound"]=>
  string(24) "ANY_TAG, IFD0, THUMBNAIL"
  ["COMPUTED"]=>
  array(2) {
    ["IsColor"]=>
    int(0)
    ["ByteOrderMotorola"]=>
    int(1)
  }
  ["StripOffsets"]=>
  float(8.9143601808023E-41)
  ["THUMBNAIL"]=>
  array(1) {
    ["StripOffsets"]=>
    float(8.9143601808023E-41)
  }
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-03-03 10:45 UTC] nikic@php.net
You likely need to introduce a byte-swap into php_ifd_get_float() and php_ifd_get_double() on big-endian architectures.
 [2020-03-09 05:57 UTC] vibhutisawant18 at gmail dot com
I added  a byte swap in php_ifd_get_float() and php_ifd_get_double(), however same behavior continues to persist.
Could you please provide with some more insights.
 [2020-03-25 05:50 UTC] vibhutisawant18 at gmail dot com
@nikic following observations were made wrt the TC behaviour on Big endian
System(s390x)
char data type is signed(-128 to 127) by default on x86 arch whereas char is
treated as unsigned(0 to 255) on s390x.
In function static float php_ifd_get_float(char *data) of
php-src/ext/exif/exif.c ,the 3rd byte (data[2]) is referring to -8(Hex:
fffffff8 ),where as its referred to 248 (Hex: f8) on s390x as char is treated as unsigned char.
Hence byte swap won't solve the issue, could you please guide us on what could possibly help to tackle the above
scenario?
 [2020-04-16 10:19 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=0b709e3409a1899caa6aaf3a5442e83524e2355c
Log: Fix bug #79336
 [2020-04-16 10:19 UTC] nikic@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 06 01:01:27 2024 UTC