Commit graph

718 commits

Author SHA1 Message Date
Niels Dossche
54e662c6f5
Revert "Port XML_GetCurrentByteIndex to public APIs"
This reverts commit 8dc799aac7.

Originally, this was going to be deprecated in libxml2 2.14, but this
didn't end up happening in the end, and the replacement function that we
used got deprecated instead. So fix the deprecation warning by reverting
to the original code.

Closes GH-18407.
2025-04-23 22:07:26 +02:00
Jakub Zelenka
acf2f4988a
Merge branch 'PHP-8.2' into PHP-8.3 2025-03-11 22:09:00 +01:00
Jakub Zelenka
4af1830356
Merge branch 'PHP-8.1' into PHP-8.2 2025-03-11 21:57:33 +01:00
Niels Dossche
0e715e71d9
Fix GHSA-wg4p-4hqh-c3g9 2025-03-11 21:50:17 +01:00
Niels Dossche
b621b3a00f
Fix GH-17187: unreachable program point in zend_hash
A bunch of different issues:
1) The referenced value is copied without incrementing the refcount.
   The reason the refcount isn't incremented is because otherwise
   the array modifications would violate the RC1 constraints.
   Solve this by copying the reference itself instead and always
   read the referenced value.
2) No type checks on the array data, so malicious scripts could
   cause type confusion bugs.
3) Potential overflow when the arrays resize and we access ctag.

Closes GH-17205.
2024-12-27 15:51:17 +01:00
Niels Dossche
14c107371c Backport 061058a9: Test fixes for libxml2 2.12.0 2024-10-12 15:12:40 +02:00
Niels Dossche
bb46b4b799 Backport 4fe82131: Backport libxml2 2.13.2 fixes (#14816)
Backproted from https://github.com/php/php-src/pull/14789
2024-10-12 15:12:40 +02:00
Niels Dossche
6c82ca2182
Fix GH-15868: Assertion failure in xml_parse_into_struct after exception
Upon unwinding from an exception, the parser state is not stable, we
should not continue updating the values if an exception was thrown.

Closes GH-15879.
2024-09-13 20:01:44 +02:00
Niels Dossche
ac8db36543
Fix GH-15868: Assertion failure in xml_parse_into_struct after exception
Upon unwinding from an exception, the parser state is not stable, we
should not continue updating the values if an exception was thrown.

Closes GH-15879.
2024-09-13 19:59:41 +02:00
Niels Dossche
459d79db95
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  [ci skip] Test is for libxml only
2024-07-06 14:41:56 +02:00
Niels Dossche
0b6289dab8
[ci skip] Test is for libxml only 2024-07-06 14:41:44 +02:00
Niels Dossche
9a337a85bf
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-14834: Error installing PHP when --with-pear is used
2024-07-06 13:52:34 +02:00
Niels Dossche
67259e451d
Fix GH-14834: Error installing PHP when --with-pear is used
libxml2 2.13 makes changes to how the parsing state is set, update our
code accordingly. In particular, it started reporting entities within
attributes, while it should only report entities inside text nodes.

Closes GH-14837.
2024-07-06 13:52:02 +02:00
Niels Dossche
a1bcaf05b0
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  NEWS for compatibility in XML
  Stop setting parse options directly
  Stop relying on lastError directly
  Stop relying on the sax2 flag directly
  Port XML_GetCurrentByteIndex to public APIs
2024-07-06 13:50:23 +02:00
Niels Dossche
e5e15fd229
Stop setting parse options directly
Setting this directly will be deprecated in libxml2 2.14.
2024-07-06 13:46:16 +02:00
Niels Dossche
823d0588f7
Stop relying on lastError directly
Reading this directly will become deprecated in libxml2 2.14.
2024-07-06 13:46:15 +02:00
Niels Dossche
6490a18271
Stop relying on the sax2 flag directly
Setting this directly will become deprecated in libxml2 2.14.
2024-07-06 13:46:15 +02:00
Niels Dossche
8dc799aac7
Port XML_GetCurrentByteIndex to public APIs
This is necessary to avoid a deprecation break in libxml2 2.14.x.
2024-07-06 13:46:15 +02:00
Niels Dossche
ecf0bb0fd1
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  [ci skip] NEWS
  Backport libxml2 2.13.2 fixes (#14816)
2024-07-04 15:37:35 +02:00
Niels Dossche
4fe821311c
Backport libxml2 2.13.2 fixes (#14816)
Backproted from https://github.com/php/php-src/pull/14789
2024-07-04 15:29:50 +02:00
Niels Dossche
77c21cab2a
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-14124: Segmentation fault on unknown address 0x0001ffff8041 with XML extension under certain memory limit (#14126)
2024-05-04 14:11:00 +02:00
Niels Dossche
427c244168
Fix GH-14124: Segmentation fault on unknown address 0x0001ffff8041 with XML extension under certain memory limit (#14126)
The ltags were not initialized, so when an OOM happens before the new value is written, uninitialized data is used.
2024-05-04 14:05:24 +02:00
Niels Dossche
8bb2a15d01 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-13517: Multiple test failures when building with --with-expat
2024-02-27 21:49:39 +01:00
Niels Dossche
552ea62e1f Fix GH-13517: Multiple test failures when building with --with-expat
The reflection failure is because the XML extension is used to check the
module dependency information, but that extension can be configured to
not depend on ext/libxml, resulting in a different output. The solution
is to check another extension instead.

The test failures in ext/xml/tests are because of different behaviour
between libxml2 and Expat error handling. These are expected differences
and the solution is to split the tests.

Closes GH-13522.
2024-02-27 21:49:01 +01:00
Niels Dossche
5be5a3dfdb Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Test fixes for libxml2 2.12.0
2023-11-29 20:53:13 +01:00
Niels Dossche
061058a9b1 Test fixes for libxml2 2.12.0 2023-11-29 20:52:01 +01:00
Niels Dossche
2bbe4fda75 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix memory leak when calling xml_parse_into_struct() twice
  Fix return type of stub of xml_parse_into_struct()
2023-09-21 19:52:21 +02:00
Niels Dossche
2aea9be3ea Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix memory leak when calling xml_parse_into_struct() twice
  Fix return type of stub of xml_parse_into_struct()
2023-09-21 19:51:14 +02:00
Niels Dossche
30f26b587a Fix memory leak when calling xml_parse_into_struct() twice
Closes GH-12254.
2023-09-21 19:49:46 +02:00
Niels Dossche
b1d9a8d321 Fix return type of stub of xml_parse_into_struct()
Closes GH-12253.
2023-09-21 19:48:40 +02:00
Derick Rethans
86afbe10e2 Merge branch 'PHP-8.2' 2023-07-31 19:57:02 +01:00
Derick Rethans
deddf4692a Merge branch 'PHP-8.1' into PHP-8.2 2023-07-31 19:54:44 +01:00
Derick Rethans
0870ebb862 Merge branch 'PHP-8.0' into PHP-8.1 2023-07-31 19:53:43 +01:00
Niels Dossche
c283c3ab0b Sanitize libxml2 globals before parsing
Fixes GHSA-3qrf-m4j2-pcrr.

To parse a document with libxml2, you first need to create a parsing context.
The parsing context contains parsing options (e.g. XML_NOENT to substitute
entities) that the application (in this case PHP) can set.
Unfortunately, libxml2 also supports providing default set options.
For example, if you call xmlSubstituteEntitiesDefault(1) then the XML_NOENT
option will be added to the parsing options every time you create a parsing
context **even if the application never requested XML_NOENT**.

Third party extensions can override these globals, in particular the
substitute entity global. This causes entity substitution to be
unexpectedly active.

Fix it by setting the parsing options to a sane known value.
For API calls that depend on global state we introduce
PHP_LIBXML_SANITIZE_GLOBALS() and PHP_LIBXML_RESTORE_GLOBALS().
For other APIs that work directly with a context we introduce
php_libxml_sanitize_parse_ctxt_options().
2023-07-31 19:47:19 +01:00
Niels Dossche
6d3433e60f Remove always-true condition from xml_utf8_decode()
decoder is already checked above
2023-07-11 11:47:54 +02:00
George Peter Banyard
d5ad75108e
More usage of known zend_str instead of C string (#11381) 2023-06-08 13:03:29 +01:00
Niels Dossche
82b05373b1 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix GH-11160: Few tests failed building with new libxml 2.11.0
2023-05-06 23:15:57 +02:00
Niels Dossche
dc1a70c244 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-11160: Few tests failed building with new libxml 2.11.0
2023-05-06 23:10:58 +02:00
Niels Dossche
7c0dfc5cf5 Fix GH-11160: Few tests failed building with new libxml 2.11.0
It's possible to categorise the failures into 2 categories:
  - Changed error message. In this case we either duplicate the test and
    modify the error message. Or if the change in error message is
    small, we use the EXPECTF matchers to make the test compatible with both
    old and new versions of libxml2.
  - Missing warnings. This is caused by a change in libxml2 where the
    parser started using SAX APIs internally [1]. In this case the
    error_type passed to php_libxml_internal_error_handler() changed from
    PHP_LIBXML_ERROR to PHP_LIBXML_CTX_WARNING because it internally
    started to use the SAX handlers instead of the generic handlers.
    However, for the SAX handlers the current input stack is empty, so
    nothing is actually printed. I fixed this by falling back to a
    regular warning without a filename & line number reference, which
    mimicks the old behaviour. Furthermore, this change now also shows
    an additional warning in a test which was previously hidden.

[1] 9a82b94a94

Closes GH-11162.
2023-05-06 23:10:07 +02:00
George Peter Banyard
81e59c6497
Improve handling of XML options
Mark boolean options as such
Warn on invalid types
Stubs info

Closes GH-10675
2023-02-26 14:34:39 +00:00
George Peter Banyard
524391bcf6
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fixed ValueError message in count_chars()
  Fixed ValueError message in substr_compare()
  The userland constants do not start with PHP_
2023-02-26 14:28:49 +00:00
George Peter Banyard
f440911057
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fixed ValueError message in count_chars()
  Fixed ValueError message in substr_compare()
  The userland constants do not start with PHP_
2023-02-26 14:28:22 +00:00
George Peter Banyard
6a5b3f0ff9
The userland constants do not start with PHP_ 2023-02-26 14:18:12 +00:00
Máté Kocsis
fc11a8abcb
Declare XML_SAX_IMPL constant in stubs (#9732) 2022-10-12 11:42:24 +02:00
George Peter Banyard
572f180b8d
Merge branch 'PHP-8.2'
* PHP-8.2:
  Use true return type for XML functions which always return true
2022-09-23 13:22:35 +01:00
George Peter Banyard
85d10cc93d
Use true return type for XML functions which always return true
And fix xml_parser_set_option() which didn't return false on failure.

Closes GH-9539
2022-09-23 13:22:13 +01:00
Bob Weinand
a01dd9feda Revert "Port all internally used classes to use default_object_handlers"
This reverts commit 94ee4f9834.

The commit was a bit too late to be included in PHP 8.2 RC1. Given it's a massive ABI break, we decide to postpone the change to PHP 8.3.
2022-09-14 11:13:23 +02:00
George Peter Banyard
951bd74038 Do early returns in xml.c
This reduces nesting clarying what preconditions are needed in each of the handler functions
2022-09-13 13:56:52 +01:00
George Peter Banyard
6aef13402e Mark _xml_decode_tag() as taking a const XML_Char*
As this is always the case and this removes unnecessary pointer casts
2022-09-13 13:56:52 +01:00
George Peter Banyard
0b8ad94b91 Refactor _xml_add_to_info()
Mark char* as const, and compute it's length once to save an expensive strlen() call
2022-09-13 13:56:52 +01:00