Skip to content

Fix bug77578.phpt - #16663

Merged
cmb69 merged 3 commits into
php:masterfrom
cmb69:cmb/bug77578.phpt
Nov 1, 2024
Merged

cmb69 merged 3 commits into
php:masterfrom
cmb69:cmb/bug77578.phpt

Conversation

@cmb69

@cmb69 cmb69 commented Nov 1, 2024

Copy link
Copy Markdown
Member

The test fails since PR #15847 has been merged. This patch should fix the test, but is certainly not complete. I haven't had the time to look closer into this issue, but it seems that the assumption that a persistent constant also has a persistent filename is not generally valid (in this case, dl() is involved). So this needs closer investigation, but this fix might be pulled to get CI back to green.

@iluuu1994 iluuu1994 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for having a look. If this only happens with dl(), it should indeed be harmless, but in the general sense internal things should be persistent. I'll let you decide whether it's worth adjusting. 🙂

cmb69 referenced this pull request Nov 1, 2024
* PHP-8.4:
  Properly initialize _override executor globals
cmb69 added 2 commits November 1, 2024 12:29
This reverts commit 2c22bd7.
`dl()` has known issues regarding permanent strings[1], so we better
avoid it, even if that means that we need to spawn two sub-processes.

[1] <php#9196>
@cmb69

cmb69 commented Nov 1, 2024

Copy link
Copy Markdown
Member Author

Indeed, this only happens with dl(), so I've adapted the test to avoid it (it's not needed to verify the bug fix anyway; was just a convenience).

@iluuu1994

Copy link
Copy Markdown
Member

Do you know why dl() results in the string being non-persistant?

@cmb69

cmb69 commented Nov 1, 2024

Copy link
Copy Markdown
Member Author

Do you know why dl() results in the string being non-persistant?

filename_str = zend_string_init(filename, strlen(filename), 0);

backtrace
>	php8ts_debug.dll!compile_string(_zend_string * source_string, const char * filename, _zend_compile_position position) Zeile 799	C
 	php8ts_debug.dll!zend_eval_stringl(const char * str, unsigned __int64 str_len, _zval_struct * retval_ptr, const char * string_name) Zeile 1342	C
 	php8ts_debug.dll!zend_eval_stringl_ex(const char * str, unsigned __int64 str_len, _zval_struct * retval_ptr, const char * string_name, bool handle_exceptions) Zeile 1396	C
 	php8ts_debug.dll!zend_eval_string_ex(const char * str, _zval_struct * retval_ptr, const char * string_name, bool handle_exceptions) Zeile 1407	C
 	php.exe!do_cli(int argc, char * * argv) Zeile 965	C
 	php.exe!main(int argc, char * * argv) Zeile 1310	C
 	[Externer Code]	

zend_eval_string_ex(exec_direct, NULL, "Command line code", 1);

So while I still think that it makes sense to rewrite the test to avoid dl(), the assumption that the filename is persistent, if the constant is persistent, is not necessarily valid. This has nothing to do with com_dotnet; simple reproducer:

php -r 'dl("curl");'

Or any other extension which registers constants, and is not already loaded.

@iluuu1994

iluuu1994 commented Nov 1, 2024 •

Copy link
Copy Markdown
Member

Oh, I just understood the problem. It's that dl() is executed while EG(current_execute_data) is set, so zend_get_executed_filename_ex() will link the current user file to the extensions constant when it shouldn't (as internal extensions don't have a file name). Not sure yet what the best fix is.

@cmb69
cmb69 marked this pull request as ready for review November 1, 2024 21:12
@cmb69
cmb69 merged commit c0136f0 into php:master Nov 1, 2024
@cmb69

cmb69 commented Nov 1, 2024

Copy link
Copy Markdown
Member Author

I have now merged this PR so we have green CI on Windows. We can cater to a more general later.

@cmb69
cmb69 deleted the cmb/bug77578.phpt branch November 1, 2024 21:15
iluuu1994 added a commit to iluuu1994/php-src that referenced this pull request Nov 7, 2024
We should only attempt to fetch the current filename for user constants. dl()
may attempt to register internal constants after execution has already started,
thus incorrectly linking the user file invoking dl().

See phpGH-16663
iluuu1994 added a commit that referenced this pull request Nov 7, 2024
We should only attempt to fetch the current filename for user constants. dl()
may attempt to register internal constants after execution has already started,
thus incorrectly linking the user file invoking dl().

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants