Commit Graph

439 Commits

Author SHA1 Message Date
Kalle Sommer Nielsen
af56fed73b Fixed bug #71534 (Type confusion in exif_read_data() leading to heap overflow in debug mode)
Unlike the original patch, this does not return an unknown format in case an unsigned compatible type cannot be found (cases for SINGLE and DOUBLE removed), as these seems rare cases according to the inline comments.

Note, the test does not test if PHP is in debug mode, although the report originally states it only occurs there only.

The fix is based on a patch by hlt99 at blinkenshell dot org
2016-08-07 05:35:46 +02:00
Kalle Sommer Nielsen
b0263db457 Added some extended info about ext/exif to phpinfo() 2016-08-07 05:11:40 +02:00
Kalle Sommer Nielsen
94cc0c8919 Remove void comment 2016-08-07 04:58:29 +02:00
Kalle Sommer Nielsen
8ac784ff13 Fix tests, although I was not able to reproduce these failures on an x86 build/Windows, this should hopefully make travis happy 2016-08-07 04:22:27 +02:00
Kalle Sommer Nielsen
8fd640f957 Added support for Sigma/Foveon EXIF tags
Note, the tag_info_array is re-used for both SIGMA and FOVEON, as their IFD headers can differ
2016-08-06 12:37:10 +02:00
Kalle Sommer Nielsen
57faafeb89 Added support for Minolta EXIF tags 2016-08-06 12:31:01 +02:00
Kalle Sommer Nielsen
1456f6a447 Added support for PENTAX EXIF tags 2016-08-06 12:24:19 +02:00
Kalle Sommer Nielsen
b147ef2bec Remove this redundant entry for Canon 2016-08-06 12:18:12 +02:00
Kalle Sommer Nielsen
5db7f1ea7e pefree() these (with persistent=0), as internally in zend_multibyte.c they do the same, and at the same time also cast them to void pointers to silence the compiler warnings. 2016-08-05 11:17:26 +02:00
Kalle Sommer Nielsen
b3124dbe12 Fix line endings, getting a little annoyed with VS' warning about mismatch 2016-08-05 11:12:51 +02:00
Kalle Sommer Nielsen
1740823864 Fixed bug #68547 (Exif Header component value check error) (Patch by sjh21a at gmail dot com)
This patch changes processing a little and causes some crafted tags to not be parsed and generate a warning.

This is a slight BC break from earlier versions, since it will no longer return the tags of that it was mismatching (see bug68799.phpt), namely the "WINXP" section and the "Author" tag is no longer returned due to this. Although this BC break is merely only for crafted tags, this can also have some real life effects on pictures re-saved from editors that can cause bad exif data writes, so lets keep it here.
2016-08-05 10:03:14 +02:00
Kalle Sommer Nielsen
aaa136e25d Added support for Sony pictures in EXIF as per requested in bug #72735
Sony is a little more interesting, as it is have a large range of tags it support in different models. For now I have added all the tags found within the Exif.Sony1 namespace.
2016-08-05 07:45:02 +02:00
Kalle Sommer Nielsen
93c0e97602 Split this test up to a 64bit version for more coverage
The 32bit version does not have the 64bit float values here, we already have 3 float tests which I guess will do for now at least
2016-08-05 07:15:34 +02:00
Nikita Popov
65b6f2013b Fix exif_imagetype() test after zpp change 2016-08-04 22:27:42 +02:00
Kalle Sommer Nielsen
4d90b1b5ea Use 'p' to validate a path in exif_imagetype() (like the other exif function already does) 2016-08-03 23:57:51 +02:00
Remi Collet
456e10eb9b - add a test for makernote (#72682)
- reduce image size
- add panasonic.jpg sample
2016-08-03 18:33:26 +02:00
Anatol Belski
be8f1580cf Merge branch 'PHP-7.1'
* PHP-7.1:
  improve the check, avoid strlen on NULL
2016-08-03 18:30:18 +02:00
Anatol Belski
8f0baa9707 Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0:
  improve the check, avoid strlen on NULL
2016-08-03 18:29:42 +02:00
Anatol Belski
138689ffb7 Merge branch 'PHP-5.6' into PHP-7.0
* PHP-5.6:
  improve the check, avoid strlen on NULL
2016-08-03 18:28:48 +02:00
Anatol Belski
9667ee4f72 improve the check, avoid strlen on NULL 2016-08-03 18:26:29 +02:00
Anatol Belski
8830b3d020 Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0:
  update NEWS
  update NEWS
  Changed the way MAKERNOTE is handled in case we do not have a matching signature (Remi).
2016-08-03 17:40:38 +02:00
Anatol Belski
0e82eb48cb Merge branch 'PHP-5.6' into PHP-7.0
* PHP-5.6:
  update NEWS
  Changed the way MAKERNOTE is handled in case we do not have a matching signature (Remi).
2016-08-03 17:39:22 +02:00
Kalle Sommer Nielsen
d5796fb298 Changed the way MAKERNOTE is handled in case we do not have a matching signature (Remi).
Before this patch, exif_process_IFD_in_MAKERNOTE() would return false, then causing the rest of the EXIF parsing to be interrupted. This is a regression from earlier which was most likely a part of a security fix for MAKERNOTE.

The new behavior is to instead of stopping to parse, to continue so we can still fetch data like thumbnail and GPS, thrus allowing yet unsupported formats to parse. If EXIF's debugging mode is enabled, a notice will display in case we do not match against a valid MAKERNOTE signature.

This should temporarily fix bug #72682 (exif_read_data() fails to read all data for some images) until I get around to debug it further.

(cherry picked from commit aabcb5481d)
2016-08-03 17:36:00 +02:00
Kalle Sommer Nielsen
c6bd054b86 Fixed bug #72682 (exif_read_data() fails to read all data for some images)
This is fixed by adding DJI signatures to the MAKERNOTE and its supported tags, list is credits to ExifTool documentation.
2016-08-03 17:33:18 +02:00
Kalle Sommer Nielsen
aabcb5481d Changed the way MAKERNOTE is handled in case we do not have a matching signature (Remi).
Before this patch, exif_process_IFD_in_MAKERNOTE() would return false, then causing the rest of the EXIF parsing to be interrupted. This is a regression from earlier which was most likely a part of a security fix for MAKERNOTE.

The new behavior is to instead of stopping to parse, to continue so we can still fetch data like thumbnail and GPS, thrus allowing yet unsupported formats to parse. If EXIF's debugging mode is enabled, a notice will display in case we do not match against a valid MAKERNOTE signature.

This should temporarily fix bug #72682 (exif_read_data() fails to read all data for some images) until I get around to debug it further.
2016-08-03 17:05:31 +02:00
Kalle Sommer Nielsen
fbb1690198 Fixed Redhat bug #1362571 (PHP not returning full results for exif_read_data function)
There are two factors for this bug fix:
 - First of all, the maximum nesting level has been increased to 150 (previously 100), I'm not sure how much an impact this will have, but increasing this value also seems to resolve PHP bug #66443 (Corrupt EXIF header: maximum directory nesting level reached for some cameras.)
  - Second, this adds support for most common Panasonic EXIF tags, again this list is based off the Exiv2 website

Note about Panasonic's format:
From what I could find, then the offset was always 12 bytes for such, the signature always had the 'P' capitalized, and the rest lower cased, followed by 3 NULL bytes

@Remi, can you review this? I'm gonna look into Sony (which is huge btw!) and your patch next
2016-08-03 11:59:30 +02:00
Kalle Sommer Nielsen
9c8c37854e Fixed bug #72735 (Samsung picture thumb not read (zero size))
It seems like there is no maker data for "Samsung", this causes the IDF tag parsing to fail, and it bails early on, despite there still is valid remaining data in image, such as the thumbnail data as reported in the bug.

I used the Exiv2 website as a reference guide for tags that's specific to Samsung's EXIF data, which should also mean that we will be able to name some of those tags more specifically now.

I have chosen again not to commit this to other branches, simply because I'm not 100% sure on the byte order and offsets for Samsung, I did some research and it seems like there are many variants, but this (very copy/pasted), entry works for this particular image and does not break any other tests. This does add a new feature I suppose, while also fixing a bug, but I will leave it to the other branch RMs to decide on how far down they will want to merge this.
2016-08-03 10:02:22 +02:00
Kalle Sommer Nielsen
aa821d8cad Revert "Fixed bug #72735 (Samsung picture thumb not read (zero size))"
This reverts commit 406dff2a02.

This seems to break more than expected and other tests seems to fail:
 - bug60150.phpt
 - bug62523_2.phpt
 - bug72603.phpt
 - bug72618.phpt

I'm gonna go do around of thinking and see if I can come up with a better fix
2016-08-03 06:10:56 +02:00
Kalle Sommer Nielsen
406dff2a02 Fixed bug #72735 (Samsung picture thumb not read (zero size))
This fix is only committed to master for now. I'm no exif expert on this matter, so someone else might want to take a look over this and merge as wanted in case this will break something.

In exif_process_IFD_in_JPEG() we loop over the tag entries and try to process the IFD tag, this is fine and all, however in case one fail to process correctly, the entire routine is aborted, which means that other possible data, such as the thumbnail data as reported in #72735 may not be read, despite it is there, perfectly valid.

Also, big props to whoever added EXIF_DEBUG, this rocks!
2016-08-03 05:39:39 +02:00
Kalle Sommer Nielsen
3e921aa9df Minor touches to the exif build script on Windows; ADD_EXTENSION_DEP() will already ERROR() out, so the WARNING() statement would never be returned anyway.
There are probably other similar cases around ext/, however the main reason for fixing this was for the typo (libxml > mbstring).
2016-08-03 04:24:17 +02:00
Anatol Belski
e0fdf261bf Merge branch 'PHP-7.0'
* PHP-7.0:
  fix test portability and expectation
2016-07-19 14:51:26 +02:00
Anatol Belski
6571a90f7f Merge branch 'PHP-5.6' into PHP-7.0
* PHP-5.6:
  fix test portability and expectation
2016-07-19 14:50:45 +02:00
Anatol Belski
bd1919504b fix test portability and expectation
The test images for #72603 and #72618 are broken, that seems to be
the cause of different test output. Seems also to be platform dependent,
so it's not reliable to depend on the exact error output.
2016-07-19 14:49:24 +02:00
Stanislav Malyshev
70d6ce3368 Merge branch 'PHP-7.0'
* PHP-7.0: (27 commits)
  fix #72519, possible OOB using imagegif
  fix #72512, invalid read or write for palette image when invalid transparent index is used
  Apparently some envs miss SIZE_MAX
  Fix tests
  Fix bug #72618: NULL Pointer Dereference in exif_process_user_comment
  Partial fix for bug #72613 - do not allow reading past error read
  Partial fix for bug #72613 - do not treat negative returns from bz2 as size_t
  Fix bug #72606: heap-buffer-overflow (write) simplestring_addn simplestring.c
  Fix for bug #72558, Integer overflow error within _gdContributionsAlloc()
  Fix bug #72603: Out of bound read in exif_process_IFD_in_MAKERNOTE
  update NEWS
  Fixed bug #72570 Segmentation fault when binding parameters on a query without placeholders
  Fix bug #72562 - destroy var_hash properly
  Fix bug #72551 and bug #72552 - check before converting size_t->int
  Fix bug #72541 - size_t overflow lead to heap corruption
  Fix bug #72533 (locale_accept_from_http out-of-bounds access)
  Fix fir bug #72520
  Fix for bug #72513
  Fix for bug #72513
  CS fix and comments with bug ID
  ...

Conflicts:
	ext/standard/basic_functions.c
2016-07-19 01:44:14 -07:00
Stanislav Malyshev
b00f8f2a5b Merge branch 'PHP-5.6' into PHP-7.0
* PHP-5.6:
  fix #72519, possible OOB using imagegif
  fix #72512, invalid read or write for palette image when invalid transparent index is used
  Apparently some envs miss SIZE_MAX
  Fix tests
  Fix bug #72618: NULL Pointer Dereference in exif_process_user_comment
  Partial fix for bug #72613 - do not treat negative returns from bz2 as size_t
  Fix bug #72606: heap-buffer-overflow (write) simplestring_addn simplestring.c
  Fix for bug #72558, Integer overflow error within _gdContributionsAlloc()
  Fix bug #72603: Out of bound read in exif_process_IFD_in_MAKERNOTE
  Fix bug #72562 - destroy var_hash properly
  Fix bug #72533 (locale_accept_from_http out-of-bounds access)
  Fix fir bug #72520
  Fix for bug #72513
  Fix for bug #72513
  CS fix and comments with bug ID
  Fix for HTTP_PROXY issue.
  5.6.24RC1
  add tests for bug #72512
  Fixed bug #72512 gdImageTrueColorToPaletteBody allows arbitrary write/read access
  Fixed bug #72479 - same as #72434

Conflicts:
	Zend/zend_virtual_cwd.c
	ext/bz2/bz2.c
	ext/exif/exif.c
	ext/session/session.c
	ext/snmp/snmp.c
	ext/standard/basic_functions.c
	main/SAPI.c
	main/php_variables.c
2016-07-19 01:39:28 -07:00
Stanislav Malyshev
4d0565b5ba Merge branch 'PHP-5.5' into PHP-5.6
* PHP-5.5:
  fix #72519, possible OOB using imagegif
  fix #72512, invalid read or write for palette image when invalid transparent index is used
  Apparently some envs miss SIZE_MAX
  Fix tests
  Fix bug #72618: NULL Pointer Dereference in exif_process_user_comment
  Partial fix for bug #72613 - do not treat negative returns from bz2 as size_t
  Fix bug #72606: heap-buffer-overflow (write) simplestring_addn simplestring.c
  Fix for bug #72558, Integer overflow error within _gdContributionsAlloc()
  Fix bug #72603: Out of bound read in exif_process_IFD_in_MAKERNOTE
  Fix bug #72562 - destroy var_hash properly
  Fix bug #72533 (locale_accept_from_http out-of-bounds access)
  Fix fir bug #72520
  Fix for bug #72513
  CS fix and comments with bug ID
  Fix for HTTP_PROXY issue.
  add tests for bug #72512
  Fixed bug #72512 gdImageTrueColorToPaletteBody allows arbitrary write/read access
  Fixed bug #72479 - same as #72434

Conflicts:
	ext/bz2/bz2.c
	main/SAPI.c
	main/php_variables.c
2016-07-19 00:53:08 -07:00
Stanislav Malyshev
1364742be9 Fix tests 2016-07-18 23:30:51 -07:00
Stanislav Malyshev
41131cd41d Fix bug #72618: NULL Pointer Dereference in exif_process_user_comment 2016-07-18 23:21:51 -07:00
Stanislav Malyshev
eebcbd5de3 Fix bug #72603: Out of bound read in exif_process_IFD_in_MAKERNOTE 2016-07-17 16:34:21 -07:00
Dmitry Stogov
323b2733f6 Fixed compilation warnings 2016-06-22 00:40:50 +03:00
Anatol Belski
3d3f11ede4 Fixed the UTF-8 and long path support in the streams on Windows.
Since long the default PHP charset is UTF-8, however the Windows part is
out of step with this important point. The current implementation in PHP
doesn't technically permit to handle UTF-8 filepath and several other
things. Till now, only the ANSI compatible APIs are being used. Here is more
about it

https://msdn.microsoft.com/en-us/library/windows/desktop/dd317752%28v=vs.85%29.aspx

The patch fixes not only issues with multibyte filenames under
incompatible codepages, but indirectly also issues with some other multibyte
encodings like BIG5, Shift-JIS, etc. by providing a clean way to access
filenames in UTF-8. Below is a small list of issues from the bug tracker,
that are getting fixed:

https://bugs.php.net/63401
https://bugs.php.net/41199
https://bugs.php.net/50203
https://bugs.php.net/71509
https://bugs.php.net/64699
https://bugs.php.net/64506
https://bugs.php.net/30195
https://bugs.php.net/65358
https://bugs.php.net/61315
https://bugs.php.net/70943
https://bugs.php.net/70903
https://bugs.php.net/63593
https://bugs.php.net/54977
https://bugs.php.net/54028
https://bugs.php.net/43148
https://bugs.php.net/30730
https://bugs.php.net/33350
https://bugs.php.net/35300
https://bugs.php.net/46990
https://bugs.php.net/61309
https://bugs.php.net/69333
https://bugs.php.net/45517
https://bugs.php.net/70551
https://bugs.php.net/50197
https://bugs.php.net/72200
https://bugs.php.net/37672

Yet more related tickets can for sure be found - on bugs.php.net, Stackoverflow
and Github. Some of the bugs are pretty recent, some descend to early
2000th, but  the user comments in there last even till today. Just for example,
bug #30195 was opened in 2004, the latest comment in there was made in 2014. It
is certain, that these bugs descend not only to pure PHP use cases, but get also
redirected from the popular PHP based projects. Given the modern systems (and
those supported by PHP) are always based on NTFS, there is no excuse to keep
these issues unresolved.

The internalization approach on Windows is in many ways different from
UNIX and Linux, while it supports and is based on Unicode. It depends on the
current system code page, APIs used and exact kind how the binary was compiled
The locale doesn't affect the way Unicode or ANSI API work. PHP in particular
is being compiled without _UNICODE defined and this is conditioned by the
way we handle strings. Here is more about it

https://msdn.microsoft.com/en-us/library/tsbaswba.aspx

However, with any system code page ANSI functions automatically convert
paths to UTF-16. Paths in some encodings incompatible with the
current system code page, won't work correctly with ANSI APIs. PHP
till now only uses the ANSI Windows APIs.

For example, on a system with the current code page 1252, the paths
in cp1252 are supported and transparently converted to UTF-16 by the
ANSI functions. Once one wants to handle a filepath encoded with cp932 on
that particular system, an ANSI or a POSIX compatible function used in
PHP will produce an erroneous result. When trying to convert that cp932 path
to UTF-8 and passing to the ANSI functions, an ANSI function would
likely interpret the UTF-8 string as some string in the current code page and
create a filepath that represents every single byte of the UTF-8 string.
These behaviors are not only broken but also disregard the documented
INI settings.

This patch solves the issies with the multibyte paths on Windows by
intelligently enforcing the usage of the Unicode aware APIs. For
functions expect Unicode (fe CreateFileW, FindFirstFileW, etc.), arguments
will be converted to UTF-16 wide chars. For functions returning Unicode
aware data (fe GetCurrentDirectoryW, etc.), resulting wide string is
converted back to char's depending on the current PHP charset settings,
either to the current ANSI codepage (this is the behavior prior to this patch)
or to UTF-8 (the default behavior).

In a particular case, users might have to explicitly set
internal_encoding or default_charset, if filenames in ANSI codepage are
necessary. Current tests show no regressions and witness that this will be an
exotic case, the current default UTF-8 encoding is compatible with any
supported system. The dependency libraries are long switching to Unicode APIs,
so some tests were also added for extensions not directly related to streams.
At large, the patch brings over 150 related tests into the core. Those target
and was run on various environments with European, Asian, etc. codepages.
General PHP frameworks was tested and showed no regressions.

The impact on the current C code base is low, the most places affected
are the Windows only places in the three files tsrm_win32.c, zend_virtual_cwd.c
and plain_wrapper.c. The actual implementation of the most of the wide
char supporting functionality is in win32/ioutil.* and win32/codepage.*,
several  low level functionsare extended in place to avoid reimplementation for
now. No performance impact was sighted. As previously mentioned, the ANSI APIs
used prior the patch perform Unicode conversions internally. Using the
Unicode  APIs directly while doing custom conversions just retains the status
quo. The ways to optimize it are open (fe. by implementing caching for the
strings converted to wide variants).

The long path implementation is user transparent. If a path exceeds the
length of _MAX_PATH, it'll be automatically prefixed with \\?\. The MAXPATHLEN
is set to 2048 bytes.

Appreciation to Pierre Joye, Matt Ficken, @algo13 and others for tips, ideas
and testing.

Thanks.
2016-06-20 12:45:39 +02:00
Stanislav Malyshev
49b1290617 Merge branch 'PHP-5.6' into PHP-7.0
* PHP-5.6:
  Fix #50845: exif_process_IFD_TAG: Use the right offset if reading from stream
2016-06-14 10:50:45 -07:00
Bartosz Dziewoński
1ab5a1b432 Fix #50845: exif_process_IFD_TAG: Use the right offset if reading from stream
When the location of the data is outside of the range we have
preloaded (for example, if it's before the beginning of the IFD
structure), we have to read it from the stream into a separate buffer.
The offset calculations in this case were incorrect, resulting in
bogus values being read for the affected fields (sometimes parts of
other fields, sometimes binary data).

The included test image, sourced from [1], is in the public domain.

[1] https://commons.wikimedia.org/wiki/File:U.S._Marines_Prepare_to_board_an_MV-22_Osprey_160509-M-AF202-041.jpg
2016-06-14 10:48:08 -07:00
Anatol Belski
25ef19f927 Merge branch 'PHP-5.6' into PHP-7.0
* PHP-5.6:
  fix/improve tests
2016-04-27 13:19:29 +02:00
Anatol Belski
a21a997478 fix/improve tests 2016-04-27 13:16:57 +02:00
Anatol Belski
33d41da347 Merge branch 'PHP-5.6' into PHP-7.0
* PHP-5.6:
  Fix memory leak
  Fix bug #72099: xml_parse_into_struct segmentation fault
  5.5.36 now
  Fix bug #72094 - Out of bounds heap read access in exif header processing
  Fix bug #72093: bcpowmod accepts negative scale and corrupts _one_ definition
  Fix bug #72061 - Out-of-bounds reads in zif_grapheme_stripos with negative offset
  Fix for bug #71912 (libgd: signedness vulnerability)
  Typo in NEWS
2016-04-27 11:45:29 +02:00
Stanislav Malyshev
e315a162da Merge branch 'PHP-5.5' into PHP-5.6
* PHP-5.5:
  Fix memory leak
  Fix bug #72099: xml_parse_into_struct segmentation fault
  5.5.36 now
  Fix bug #72094 - Out of bounds heap read access in exif header processing
  Fix bug #72093: bcpowmod accepts negative scale and corrupts _one_ definition
  Fix bug #72061 - Out-of-bounds reads in zif_grapheme_stripos with negative offset
  Fix for bug #71912 (libgd: signedness vulnerability)
  Typo in NEWS

Conflicts:
	configure.in
	main/php_version.h
2016-04-26 23:48:41 -07:00
Stanislav Malyshev
082aecfc3a Fix bug #72094 - Out of bounds heap read access in exif header processing 2016-04-24 19:33:52 -07:00
Nikita Popov
5602f64213 Eliminate usages of _PP macros
These are either in debug code (fix them), commented out (drop
them) or in dead compatibility macros (drop them).

One usage was in php_stream_get_from_zval(), which we have not used
since at least PHP 5.2 and, judging from the fact that nobody
complained about it causing compile errors in PHP 7, nobody else
uses it either, so drop it.

There are still remaining uses in mysqli embedded and odbc birdstep.
These probably need to be dropped outright.
2016-03-03 23:20:12 +01:00
Nikita Popov
1ac152938c Move semicolon into TSRMLS_CACHE_EXTERN/DEFINE
Also re bug #71575.
2016-03-03 16:50:01 +01:00