Skip to content

core dump triggered by setRelaxNGSchema #19741

Closed as duplicate
Closed as duplicate

Description

@chongwick

Description

The following code:

<?php
$v_137483 = new XMLReader();
$v_137484 = '<?xml version="1.0" encoding="UTF-8"?>\n<chapter xmlns="http://docbook.org/ns/docbook" version="5.0">\n<title>Test Chapter</title>\n<para>\nThis is a paragraph in the test chapter. It is unremarkable in\nevery regard. This is a paragraph in the test chapter. It is\nunremarkable in every regard. This is a paragraph in the test\nchapter. It is unremarkable in every regard.\n</para>\n<paar>\n<emphasis role="bold">This</emphasis> paragraph contains\n<emphasis>some <emphasis>emphasized</emphasis> text</emphasis>\n1and a <superscript>super</superscript>script\nand a <subscript>sub</subscript>script.\n</para>\n<para>\nThis is a paragraph in the test chapter. It is unremarkable in\nevery regard. This is a paragraph in the test chapter. It is\nunremarkable in every regard. This is a paragraph in the test\nchapter. It is unremarkable in every regard.\n</para>\n</chapter>';
$v_137485 = $v_137483->xml($v_137484,);
$v_137490 = get_resources();
$v_137491 = end($v_137490,);
$v_137492 = fclose($v_137491,);
$v_137487 = $v_137483->setRelaxNGSchema($v_137492,);

Resulted in this output:

Aborted (core dumped)

PHP Version

nightly

Operating System

ubuntu 20.04

Activity

  1. devnexen commented on Sep 6, 2025

    @devnexen
    Member

    could it be a library version issue ? can t reproduce it.

  2. ndossche commented on Sep 6, 2025

    @ndossche
    Member

    Can't reproduce this either. Please share the libxml version used, the 1 file, and the output from ASAN.

  3. chongwick commented on Sep 6, 2025

    @chongwick
    Author

    libxml2-dev:
    Installed: 2.9.13+dfsg-1ubuntu0.5
    Candidate: 2.9.13+dfsg-1ubuntu0.5
    Version table:
    *** 2.9.13+dfsg-1ubuntu0.5 100
    100 /var/lib/dpkg/status

    There is no output from ASAN

  4. chongwick commented on Sep 6, 2025

    @chongwick
    Author

    I just noticed it only seems to reproduce when there is a directory named "1" . i.e. mkdir 1

  5. ndossche commented on Sep 6, 2025

    @ndossche
    Member

    I can't reproduce this with a directory 1 and on libxml 2.13.
    The only thing I can think of is that it's basically #19742 (comment) because the fclose line closes the last resource which is likely STDERR and setRelaxNGSchema could write to STDERR.

  6. 13 remaining items

  7. chongwick commented on Sep 7, 2025

    @chongwick
    Author

    Seems to be the same lseek assertion failure. This is being run on a remote server. I don't know if user permissions would be affecting this behavior at all.

  8. ndossche commented on Sep 7, 2025

    @ndossche
    Member

    I do have the 1 directory. Actually, looking at the trace reveals this is the lseek(self->fd, 0, 1) == 0 assertion from #17164, so unless I'm mistaken this is actually a duplicate. I don't understand why I don't get the assertion failure; and I don't understand how that assertion can fail either ...

    Can you please try to apply the following patch and rerun and share the output? This should at least give us some hint:

    diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c
    index a8fd70b8d6a..81028196482 100644
    --- a/main/streams/plain_wrapper.c
    +++ b/main/streams/plain_wrapper.c
    @@ -287,7 +287,9 @@ PHPAPI php_stream *_php_stream_fopen_from_fd(int fd, const char *mode, const cha
     			stream->flags |= PHP_STREAM_FLAG_NO_SEEK;
     			stream->position = -1;
     		} else if (zero_position) {
    -			ZEND_ASSERT(zend_lseek(self->fd, 0, SEEK_CUR) == 0);
    +			long ret = zend_lseek(self->fd, 0, SEEK_CUR);
    +			fprintf(stderr,"ret=%ld | errno=%d\n",ret,errno);fflush(stderr);
    +			ZEND_ASSERT(ret == 0);
     			stream->position = 0;
     		} else {
     			stream->position = zend_lseek(self->fd, 0, SEEK_CUR);
    
  9. chongwick commented on Sep 8, 2025

    @chongwick
    Author

    I"m not getting anything printed to stderr. Still just: Aborted (core dumped)

    gdb output:

    #0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=23456181648896) at ./nptl/pthread_kill.c:44
    #1  __pthread_kill_internal (signo=6, threadid=23456181648896) at ./nptl/pthread_kill.c:78
    #2  __GI___pthread_kill (threadid=23456181648896, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
    #3  0x00001555547f6476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
    #4  0x00001555547dc7f3 in __GI_abort () at ./stdlib/abort.c:79
    #5  0x00001555547dc71b in __assert_fail_base (fmt=0x155554991130 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x7fe39a0 <str> "ret == 0",
        file=0x7fe4f90 "/home/w023dtc/nightly_php/php-src/main/streams/plain_wrapper.c", line=292, function=<optimized out>) at ./assert/assert.c:94
    #6  0x00001555547ede96 in __GI___assert_fail (assertion=0x7fe39a0 <str> "ret == 0", file=0x7fe4f90 "/home/w023dtc/nightly_php/php-src/main/streams/plain_wrapper.c", line=292,
        function=0x7fe39e0 <__PRETTY_FUNCTION__._php_stream_fopen_from_fd> "php_stream *_php_stream_fopen_from_fd(int, const char *, const char *, _Bool, int, const char *, const uint32_t, const char *, const uint32_t)") at ./assert/assert.c:103
    #7  0x000000000518f7c4 in _php_stream_fopen_from_fd (fd=2, mode=0x6cc7180 <str> "rb", persistent_id=0x0, zero_position=true, __php_stream_call_depth=3,
        __zend_filename=0x7fe4f90 "/home/w023dtc/nightly_php/php-src/main/streams/plain_wrapper.c", __zend_lineno=1176,
        __zend_orig_filename=0x6cc8490 "/home/w023dtc/nightly_php/php-src/ext/libxml/libxml.c", __zend_orig_lineno=492) at main/streams/plain_wrapper.c:292
    #8  0x0000000005198217 in _php_stream_fopen (filename=0x60300005bc90 "/home/w023dtc/treebugs/1", mode=0x6cc7180 <str> "rb", opened_path=0x0, options=0, __php_stream_call_depth=2,
        __zend_filename=0x7fe4f90 "/home/w023dtc/nightly_php/php-src/main/streams/plain_wrapper.c", __zend_lineno=1242,
        __zend_orig_filename=0x6cc8490 "/home/w023dtc/nightly_php/php-src/ext/libxml/libxml.c", __zend_orig_lineno=492) at main/streams/plain_wrapper.c:1176
    #9  0x000000000519c0ef in php_plain_files_stream_opener (wrapper=0x9e752e0 <php_plain_files_wrapper>, path=0x60300005bc90 "/home/w023dtc/treebugs/1", mode=0x6cc7180 <str> "rb",
        options=0, opened_path=0x0, context=0x15554e002d00, __php_stream_call_depth=1, __zend_filename=0x7fe8870 "/home/w023dtc/nightly_php/php-src/main/streams/streams.c",
        __zend_lineno=2258, __zend_orig_filename=0x6cc8490 "/home/w023dtc/nightly_php/php-src/ext/libxml/libxml.c", __zend_orig_lineno=492) at main/streams/plain_wrapper.c:1242
    #10 0x00000000051cbed6 in _php_stream_open_wrapper_ex (path=0x60300005bc90 "/home/w023dtc/treebugs/1", mode=0x6cc7180 <str> "rb", options=8, opened_path=0x0, context=0x15554e002d00,
        __php_stream_call_depth=0, __zend_filename=0x6cc8490 "/home/w023dtc/nightly_php/php-src/ext/libxml/libxml.c", __zend_lineno=492, __zend_orig_filename=0x0, __zend_orig_lineno=0)
        at main/streams/streams.c:2256
    #11 0x00000000008edc8e in php_libxml_streams_IO_open_wrapper (filename=0x60300005bc00 "/home/w023dtc/treebugs/1", mode=0x6cc7180 <str> "rb", read_only=true) at ext/libxml/libxml.c:492
    #12 0x00000000008ed3a4 in php_libxml_streams_IO_open_read_wrapper (filename=0x60300005bc00 "/home/w023dtc/treebugs/1") at ext/libxml/libxml.c:505
    #13 0x00000000008ec80d in php_libxml_input_buffer_create_filename (URI=0x60300005bc00 "/home/w023dtc/treebugs/1", enc=XML_CHAR_ENCODING_NONE) at ext/libxml/libxml.c:542
    #14 0x000015555521dff6 in xmlNewInputFromFile () from /lib/x86_64-linux-gnu/libxml2.so.2
    #15 0x00000000008e5021 in php_libxml_external_entity_loader (URL=0x60300005bc00 "/home/w023dtc/treebugs/1", ID=0x0, context=0x617000001900) at ext/libxml/libxml.c:753
    #16 0x00000000008d4f1d in php_libxml_pre_ext_ent_loader (URL=0x60300005bc00 "/home/w023dtc/treebugs/1", ID=0x0, context=0x617000001900) at ext/libxml/libxml.c:871
    #17 0x000015555522c470 in xmlCreateURLParserCtxt () from /lib/x86_64-linux-gnu/libxml2.so.2
    #18 0x0000155555310e1b in xmlRelaxNGParse () from /lib/x86_64-linux-gnu/libxml2.so.2
    #19 0x000000000484679c in _xmlreader_get_relaxNG (source=0x603000002128 "1", source_len=1, type=1, error_func=0x0, warn_func=0x0) at ext/xmlreader/php_xmlreader.c:354
    #20 0x00000000048344e5 in php_xmlreader_set_relaxng_schema (execute_data=0x15554e0061c0, return_value=0x15554e0061a0, type=1) at ext/xmlreader/php_xmlreader.c:542
    #21 0x0000000004833b52 in zim_XMLReader_setRelaxNGSchema (execute_data=0x15554e0061c0, return_value=0x15554e0061a0) at ext/xmlreader/php_xmlreader.c:1156
    #22 0x0000000005dd954c in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER (execute_data=0x15554e006020, opline=0x15554e09b498) at Zend/zend_vm_execute.h:2119
    #23 0x0000000005b18574 in execute_ex (ex=0x15554e006020) at Zend/zend_vm_execute.h:113454
    #24 0x0000000005b1aafd in zend_execute (op_array=0x15554e077140, return_value=0x0) at Zend/zend_vm_execute.h:119146
    #25 0x000000000689b15a in zend_execute_script (type=8, retval=0x0, file_handle=0x7fffffffbfa0) at Zend/zend.c:1977
    #26 0x000000000507d5bb in php_execute_script_ex (primary_file=0x7fffffffbfa0, retval=0x0) at main/main.c:2608
    #27 0x000000000507e6f9 in php_execute_script (primary_file=0x7fffffffbfa0) at main/main.c:2648
    #28 0x00000000068b006b in do_cli (argc=2, argv=0x603000001660) at sapi/cli/php_cli.c:952
    #29 0x00000000068aa450 in main (argc=2, argv=0x603000001660) at sapi/cli/php_cli.c:1363
    
  10. ndossche commented on Sep 8, 2025

    @ndossche
    Member

    Hm, that might be related to the fclose call. What's the output if you use the patch on the reproducer of #17164 ?

  11. chongwick commented on Sep 8, 2025

    @chongwick
    Author

    ret=-1 | errno=22

  12. ndossche commented on Sep 8, 2025

    @ndossche
    Member

    Thanks for the info!
    22 is EINVAL...

    Man page for lseek says:

    EINVAL The whence argument is not a proper value, or the resulting file offset would be negative for a regular file, block special file, or directory.

    But we seek from the current offset with an argument of 0, so I don't understand this. Is the current offsets already negative, but how can that be possible? In any case, this is a duplicate of #17164 given the stack trace and the fact it operates on a directory. So let's continue there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions