Skip to content

[DOM] Register id attributes set via setAttribute() in XML documents - #298

Closed
iliaal wants to merge 58 commits into
masterfrom
fix/dom-setattribute-id-master
Closed

iliaal wants to merge 58 commits into
masterfrom
fix/dom-setattribute-id-master

Conversation

@iliaal

@iliaal iliaal commented Aug 24, 2026

Copy link
Copy Markdown
Owner

getElementById() only found dynamically created id attributes in HTML documents because the registration helper restricted the XML_ATTRIBUTE_ID flag to XML_HTML_DOCUMENT_NODE, so Dom\XMLDocument::getElementById() returned null after setAttribute("id", ...) though the id property had registered. The restriction is dropped so modern XML documents register an un-namespaced id attribute, setIdAttribute(false) still unregisters, and legacy DOMDocument stays unchanged because every helper call site sits behind spec mode. A phpt covers set, re-set, setAttributeNS, removal and setIdAttribute(false).

@iliaal
iliaal force-pushed the fix/dom-setattribute-id-master branch from 5f9a6b6 to c47910e Compare August 26, 2026 12:56
devnexen and others added 29 commits September 17, 2026 20:06
php_sock_array_to_fd_set() returned a flag rather than the socket count, so
PHP_SAFE_MAX_FD() got a zero and never fired. Sets larger than FD_SETSIZE
were quietly truncated and select() reported on the survivors.

Close phpGH-23632
* PHP-8.4:
  ext/sockets: socket_select() silent set truncation on Windows.
* PHP-8.5:
  ext/sockets: socket_select() silent set truncation on Windows.
Since it doesn't have an $errors property
…php#23716)

Given that the knowledge that the fetch callback is not null is based on
validation that was done separately, and there are indeed entries in
`mysqlnd_ps_fetch_functions` where the callback is null, add a `ZEND_ASSERT`
that the function is not null as a hardening measure.
- Reuse the basename string for PATHINFO_BASENAME
and extensionless PATHINFO_FILENAME results.
- Share the last-dot lookup for extension and filename
when returning PATHINFO_ALL.
- (From my perspective) cleaner code.
Co-authored-by: jrfnl <jrfnl@users.noreply.github.com>
Now the latest version of libmagic is 5.48. This
commit update the bundled libmagic to that
version.
…ion___unserialize (php#23759)

LVAL cannot be read if the type is still UNDEF. Check initialization to
fix this.
Randomizer doesn't have this because it uses read_property.
…ansformation.

Fix php#23730

Importing a stylesheet from a php:function callback freed the stylesheet
libxslt was still applying, and the transformation methods kept using the
stale pointer to save the result. The transformation depth is now tracked
on the object and importStylesheet() throws while it is non-zero.

Close phpGH-23737
* PHP-8.4:
  ext/xsl: XSLTProcessor::importStylesheet() use-after-free during a transformation.
* PHP-8.5:
  ext/xsl: XSLTProcessor::importStylesheet() use-after-free during a transformation.
… callback.

Fix php#23747

ZipArchive::close() called from a progress or cancel callback ran a
nested zip_close() that failed, then zip_discard() freed the archive
while the outer zip_close() from close() or open() was still using it.
Track the close in progress and throw an Error from close() and open()
meanwhile.

Close phpGH-23749
* PHP-8.4:
  ext/zip: ZipArchive::close() use-after-free from a progress or cancel callback.
* PHP-8.5:
  ext/zip: ZipArchive::close() use-after-free from a progress or cancel callback.

# Conflicts:
#	ext/zip/php_zip.c
#	ext/zip/php_zip.h
* ext/mbstring: Update to Unicode 18.0

Previously:
 - php#15898
 - 0fdffc1
 - php#7502
 - php#14680

* Update NEWS and UPGRADING
…luation

Reconstructing the object from a php:function callback freed the context
libxml2 was still evaluating, and php_xpath_eval() wrote back into it once
the evaluation returned. The evaluation depth is now tracked on the object
and __construct() throws while it is non-zero.

Close phpGH-23735
* PHP-8.4:
  Fix phpGH-23729: DOMXPath::__construct() use-after-free during an evaluation
* PHP-8.5:
  Fix phpGH-23729: DOMXPath::__construct() use-after-free during an evaluation
And thus should never be allowed to be qualified, as this lead to other bugs such as it not considered to be a built-in type by Reflection if it had a namespace component.

We *may* want to extend the unqualified restriction to self and parent in the future.

Closes phpGH-23768
If we have a valid FCC there is no need to assign to the FCI.object field as it is only used for callability checks in conjunction with the FCI.function_namefield.
Moreover, in many cases we can use an engine API to set up the structs for us instead of doing it manually.

This in preparation for the removal of the FCI.object field in the future.
jvoisin and others added 27 commits September 19, 2026 19:10
…p#23775)

After 93fd714, we just return the copy of the string when the mult
parameter of str_repeat is 1, that is to repeat the string 1 time. But
this cause inconsistency in this test. When the rand number is 1, it
won't allocate any byte. So the test will fail.
The prompt parser ran as a do-while, so an empty cli.prompt executed
the body on the terminator and scanned past it. Use a while loop and
smart_str_extract(), which returns the interned empty string when
nothing was appended. No regression test: extra unicode warnings from
the over-read depend on heap contents, so a .phpt cannot pin the bug
red-before.

Closes phpGH-23415
* PHP-8.4:
  Fix heap over-read in cli_get_prompt() for empty cli.prompt
* PHP-8.5:
  Fix heap over-read in cli_get_prompt() for empty cli.prompt
init_process_info() memset the pointer parameter instead of the
PROCESS_INFORMATION structure it points at, leaving the struct
uninitialized before CreateProcessW(). Zero it through the pointer.

find_comspec_nt() dereferences *comspec in its cleanup while the
caller only assigns it on success, so a failed SearchPathW() read an
indeterminate value. Initialize the caller's variable to NULL.

set_proc_descriptor_to_blackhole() tested CreateFileA() against NULL,
but CreateFileA() signals failure with INVALID_HANDLE_VALUE, so a
failed open went undetected and an invalid handle was inherited by
the child. Test against INVALID_HANDLE_VALUE.

Closes phpGH-23412
* PHP-8.4:
  Fix three Win32-only defects in proc_open descriptor handling
* PHP-8.5:
  Fix three Win32-only defects in proc_open descriptor handling
…tructions with callable conversion

Call level counter was broken: ZEND_CALLABLE_CONVERT was forgotten.

Closes phpGH-23777.
* PHP-8.4:
  Fix OSS-Fuzz #546798343: Heap-buffer-overflow in zend_delete_call_instructions with callable conversion
* PHP-8.5:
  Fix OSS-Fuzz #546798343: Heap-buffer-overflow in zend_delete_call_instructions with callable conversion
* PHP-8.5:
  ext/zlib: honor preset dictionary for raw inflate with non-default window
…ndow

inflate_init() applies the preset dictionary eagerly for raw streams via
inflateSetDictionary(), gated on encoding == PHP_ZLIB_ENCODING_RAW. But
encoding is first adjusted by the window size (encoding += 15 - window),
so a raw stream with a non-default window no longer equals
PHP_ZLIB_ENCODING_RAW and the dictionary is silently dropped; raw streams
carry no header and never emit Z_NEED_DICT, so inflate_add()'s deferred
path never applies it either. Gate on the pre-adjustment encoding. The
deflate side already applies the dictionary unconditionally, so the
roundtrip was broken for this case.

Closes phpGH-22381
php#21882)

Both functions can return NULL on libintl-internal allocation failure,
which RETURN_STRING then fed to strlen(NULL) and crashed. Throw an
Error in that case instead, leaving the existing string return type
intact (no static-analysis fallout from a widened signature).

The dir==NULL query path of bindtextdomain keeps its RETURN_FALSE
because musl returns NULL there to signal an unbound domain, which is
not an error condition.
Uri\WhatWg\Url::__construct() and Uri\WhatWg\UrlBuilder::build() now set $softErrors to an empty array when URL processing throws an exception, instead of preserving its value.
The JIT config was accidentally removed in php@f009ad0
… base URL (php#23526)

Add support for passing a non-null $baseUrl parameter for Uri\WhatWg\UrlBuilder::build().

RFC: https://wiki.php.net/rfc/uri_followup#uri_building
When the supplied key is shorter than the cipher's key length,
php_openssl_cipher_init() allocates a heap buffer, copies the key into
it and zero-pads it to the required length. openssl_encrypt() and
openssl_decrypt() then efree() this buffer without wiping it, leaving
the raw symmetric key in a reclaimed heap chunk where it can later be
exposed through an uninitialized-heap read, a core dump or /proc.

Scrub the buffer with ZEND_SECURE_ZERO() before freeing it, matching
what ext/hash, ext/standard/crypt* and ext/sodium already do for key
material. At the free site password_len has already been set to the
full allocation size, so the whole buffer is cleared.
The x86 matcher folds v = BINOP(a, b); c = CMP(v, 0); GUARD(c) into
IR_GUARD_JCC_INT, emitting the BINOP, dropping the CMP and branching on
the flags the BINOP left, but it only required the BINOP to precede the
CMP in the IR. Once GCM hoists a loop-invariant BINOP into a dominating
block, the jcc reads flags the intervening code has clobbered and the
guard fires on whatever is in EFLAGS. Require the BINOP to sit in the
guard's block and allow only snapshots between the comparison and the
guard, the way ir_match_fuse_load() pairs ir_in_same_block() with
ir_match_has_mem_deps(). The sibling MEM_BINOP fold already checks the
block, the IF side folds are pinned by full ref adjacency, and
ir_aarch64.dasc has no guard fold.

Mirrors the upstream fix dstogov/ir@51107a3.

Fixes phpGH-23693
Closes phpGH-23711
* PHP-8.4:
  Fix phpGH-23693: JIT guard branches on stale flags across basic blocks
* PHP-8.5:
  Fix phpGH-23693: JIT guard branches on stale flags across basic blocks
getElementById() relies on the XML_ATTRIBUTE_ID flag, which
dom_check_register_attribute_id() set only for HTML documents, leaving
Dom\XMLDocument::getElementById() blind to ids assigned through
setAttribute(), setAttributeNS() and setAttributeNode(). Drop the
document-type restriction so modern XML documents register an un-namespaced
id attribute; setIdAttribute(false) still unregisters and legacy
DOMDocument is unchanged because every call site sits behind spec mode.
@iliaal
iliaal force-pushed the fix/dom-setattribute-id-master branch from c47910e to a4cf1b6 Compare September 20, 2026 16:11
@iliaal

iliaal commented Sep 20, 2026

Copy link
Copy Markdown
Owner Author

Promoted upstream as php#23801.

@iliaal iliaal closed this Sep 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.