Skip to content

Commit 0b709e3

Browse files
committed
Fix bug #79336
Make reading of floats and doubles host-endian independent.
1 parent e88e9af commit 0b709e3

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ PHP NEWS
1111
. Fixed bug #78221 (DOMNode::normalize() doesn't remove empty text nodes).
1212
(cmb)
1313

14+
- EXIF:
15+
. Fixed bug #79336 (ext/exif/tests/bug79046.phpt fails on Big endian arch).
16+
(Nikita)
17+
1418
- MBString:
1519
. Fixed bug #79441 (Segfault in mb_chr() if internal encoding is unsupported).
1620
(Girgias)

ext/exif/exif.c

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,7 @@ static signed short php_ifd_get16s(void *value, int motorola_intel)
14871487
}
14881488
/* }}} */
14891489

1490-
/* {{{ php_ifd_get32s
1490+
/* {{{ php_ifd_get32u
14911491
* Convert a 32 bit unsigned value from file's native byte order */
14921492
static unsigned php_ifd_get32u(void *void_value, int motorola_intel)
14931493
{
@@ -1506,6 +1506,33 @@ static unsigned php_ifd_get32u(void *void_value, int motorola_intel)
15061506
}
15071507
/* }}} */
15081508

1509+
/* {{{ php_ifd_get64u
1510+
* Convert a 64 bit unsigned value from file's native byte order */
1511+
static uint64_t php_ifd_get64u(void *void_value, int motorola_intel)
1512+
{
1513+
uchar *value = (uchar *) void_value;
1514+
if (motorola_intel) {
1515+
return ((uint64_t)value[0] << 56)
1516+
| ((uint64_t)value[1] << 48)
1517+
| ((uint64_t)value[2] << 40)
1518+
| ((uint64_t)value[3] << 32)
1519+
| ((uint64_t)value[4] << 24)
1520+
| ((uint64_t)value[5] << 16)
1521+
| ((uint64_t)value[6] << 8 )
1522+
| ((uint64_t)value[7] );
1523+
} else {
1524+
return ((uint64_t)value[7] << 56)
1525+
| ((uint64_t)value[6] << 48)
1526+
| ((uint64_t)value[5] << 40)
1527+
| ((uint64_t)value[4] << 32)
1528+
| ((uint64_t)value[3] << 24)
1529+
| ((uint64_t)value[2] << 16)
1530+
| ((uint64_t)value[1] << 8 )
1531+
| ((uint64_t)value[0] );
1532+
}
1533+
}
1534+
/* }}} */
1535+
15091536
/* {{{ php_ifd_get32u
15101537
* Convert a 32 bit signed value from file's native byte order */
15111538
static unsigned php_ifd_get32s(void *value, int motorola_intel)
@@ -1547,17 +1574,15 @@ static void php_ifd_set32u(char *data, size_t value, int motorola_intel)
15471574
/* }}} */
15481575

15491576
static float php_ifd_get_float(char *data) {
1550-
/* Copy to avoid alignment issues */
1551-
float f;
1552-
memcpy(&f, data, sizeof(float));
1553-
return f;
1577+
union { uint32_t i; float f; } u;
1578+
u.i = php_ifd_get32u(data, 0);
1579+
return u.f;
15541580
}
15551581

15561582
static double php_ifd_get_double(char *data) {
1557-
/* Copy to avoid alignment issues */
1558-
double f;
1559-
memcpy(&f, data, sizeof(double));
1560-
return f;
1583+
union { uint64_t i; double f; } u;
1584+
u.i = php_ifd_get64u(data, 0);
1585+
return u.f;
15611586
}
15621587

15631588
#ifdef EXIF_DEBUG

0 commit comments

Comments
 (0)