Skip to content

JIT: Fix JIT ASSIGN_DIM undefined OP_DATA and dim reporting on non-array containers - #24665

Closed
jorgsowa wants to merge 2 commits into
php:PHP-8.4from
jorgsowa:fix-jit-assign-dim-undef-op-data
Closed

jorgsowa wants to merge 2 commits into
php:PHP-8.4from
jorgsowa:fix-jit-assign-dim-undef-op-data

Conversation

@jorgsowa

Copy link
Copy Markdown
Contributor

In function JIT, zend_jit_assign_dim_helper() read an undefined OP_DATA before checking the container type. The VM reads it only when it actually assigns, so the JIT reported warnings in a different order, or where the VM reports none:

Code VM Function JIT
$x = 1.5; $x[0] = $undef; Error: Cannot use a scalar value as an array extra Undefined variable warning before the Error
$x = 'ab'; $x[] = $undef; Error: [] operator not supported for strings extra Undefined variable warning before the Error
$x = false; $x[0] = $undef; Deprecated (false to array), then Undefined variable Undefined variable, then Deprecated
$x = 1.5; $x[$undef] = 1; Error: Cannot use a scalar value as an array extra Undefined variable warning before the Error

The helper now checks for an undefined value only on the false path, after the deprecation, and no longer reports an undefined key on the scalar path. The generated JIT code is unchanged, and the helper is slightly smaller at -O2 (183 instructions instead of 207 on arm64).

…ontainers

Report an undefined OP_DATA only when the value is assigned, after the
false to array deprecation, and never report an undefined dim before
"Cannot use a scalar value as an array", matching the VM.
@jorgsowa jorgsowa self-assigned this Oct 24, 2026
@jorgsowa
jorgsowa requested a review from dstogov as a code owner October 24, 2026 22:25
Comment thread ext/opcache/jit/zend_jit_helpers.c Resolved
@jorgsowa jorgsowa closed this in 85d2cd6 Nov 22, 2026
@Girgias

Girgias commented Nov 23, 2026

Copy link
Copy Markdown
Member

This causes the nightly MSAN build to fail:

  ========DIFF========
       Automatic conversion of false to array is deprecated
       Undefined variable $undef
  003- int(1)
  003+ ==179148==WARNING: MemorySanitizer: use-of-uninitialized-value
  004+     #0 0x5636e9a0e32c in zend_assign_to_variable_ex /home/runner/work/php-src/php-src/Zend/zend_execute.h:191:7
  005+     #1 0x5636e93a5dc9 in ZEND_ASSIGN_DIM_SPEC_CV_CONST_OP_DATA_CV_HANDLER /home/runner/work/php-src/php-src/Zend/zend_vm_execute.h:44588:12
  006+     #2 0x5636e926853c in execute_ex /home/runner/work/php-src/php-src/Zend/zend_vm_execute.h:58741:7
  007+     #3 0x5636e926ae40 in zend_execute /home/runner/work/php-src/php-src/Zend/zend_vm_execute.h:64393:2
  008+     #4 0x5636ea238461 in zend_execute_script /home/runner/work/php-src/php-src/Zend/zend.c:1943:3
  009+     #5 0x5636e8547e38 in php_execute_script_ex /home/runner/work/php-src/php-src/main/main.c:2615:13
  010+     #6 0x5636e85497f5 in php_execute_script /home/runner/work/php-src/php-src/main/main.c:2655:9
  011+     #7 0x5636ea2598b2 in do_cli /home/runner/work/php-src/php-src/sapi/cli/php_cli.c:946:5
  012+     #8 0x5636ea252243 in main /home/runner/work/php-src/php-src/sapi/cli/php_cli.c:1333:18
  013+     #9 0x7f9760a29d8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) (BuildId: 12b87db2df813df96f66d6f02dd18ea5c8b7cf8d)
  014+     #10 0x7f9760a29e3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f) (BuildId: 12b87db2df813df96f66d6f02dd18ea5c8b7cf8d)
  015+     #11 0x5636e4e01e64 in _start (/home/runner/work/php-src/php-src/sapi/cli/php+0x201e64) (BuildId: 8ed85636c3103a59a58074952025d3a19c0e3995)
  016+ 
  017+   Uninitialized value was created by a heap deallocation
  018+     #0 0x5636e4e307ac in free (/home/runner/work/php-src/php-src/sapi/cli/php+0x2307ac) (BuildId: 8ed85636c3103a59a58074952025d3a19c0e3995)
  019+     #1 0x5636e8d16479 in tracked_free /home/runner/work/php-src/php-src/Zend/zend_alloc.c:3330:2
  020+     #2 0x5636e8cce2f1 in _efree /home/runner/work/php-src/php-src/Zend/zend_alloc.c:2892:3
  021+     #3 0x5636e9bc61e6 in zend_array_destroy /home/runner/work/php-src/php-src/Zend/zend_hash.c:2086:2
  022+     #4 0x5636ea1b9efb in rc_dtor_func /home/runner/work/php-src/php-src/Zend/zend_variables.c:57:2
  023+     #5 0x5636e9a0ca90 in zend_assign_to_variable /home/runner/work/php-src/php-src/Zend/zend_execute.h:179:4
  024+     #6 0x5636e933cb41 in ZEND_ASSIGN_SPEC_VAR_CONST_RETVAL_UNUSED_HANDLER /home/runner/work/php-src/php-src/Zend/zend_vm_execute.h:25332:11
  025+     #7 0x5636e926853c in execute_ex /home/runner/work/php-src/php-src/Zend/zend_vm_execute.h:58741:7
  026+     #8 0x5636e91d7ac0 in zend_call_function /home/runner/work/php-src/php-src/Zend/zend_execute_API.c:1028:3
  027+     #9 0x5636e91ce217 in _call_user_function_impl /home/runner/work/php-src/php-src/Zend/zend_execute_API.c:806:9
  028+     #10 0x5636ea22b7f2 in zend_error_zstr_at /home/runner/work/php-src/php-src/Zend/zend.c:1549:10
  029+     #11 0x5636ea22f8fd in zend_error_va_list /home/runner/work/php-src/php-src/Zend/zend.c:1603:2
  030+     #12 0x5636ea230416 in zend_error_unchecked /home/runner/work/php-src/php-src/Zend/zend.c:1677:2
  031+     #13 0x5636e99eee62 in zval_undefined_cv /home/runner/work/php-src/php-src/Zend/zend_execute.c:279:3
  032+     #14 0x5636e99f8278 in _get_zval_ptr_cv_BP_VAR_R /home/runner/work/php-src/php-src/Zend/zend_execute.c:352:10
  033+     #15 0x5636e93a5b4b in ZEND_ASSIGN_DIM_SPEC_CV_CONST_OP_DATA_CV_HANDLER /home/runner/work/php-src/php-src/Zend/zend_vm_execute.h:44587:12
  034+     #16 0x5636e926853c in execute_ex /home/runner/work/php-src/php-src/Zend/zend_vm_execute.h:58741:7
  035+     #17 0x5636e926ae40 in zend_execute /home/runner/work/php-src/php-src/Zend/zend_vm_execute.h:64393:2
  036+     #18 0x5636ea238461 in zend_execute_script /home/runner/work/php-src/php-src/Zend/zend.c:1943:3
  037+     #19 0x5636e8547e38 in php_execute_script_ex /home/runner/work/php-src/php-src/main/main.c:2615:13
  038+ 
  039+ SUMMARY: MemorySanitizer: use-of-uninitialized-value /home/runner/work/php-src/php-src/Zend/zend_execute.h:191:7 in zend_assign_to_variable_ex
  040+ Exiting
  ========DONE========
  FAIL JIT ASSIGN_DIM: container converted from false is overwritten while reporting undefined OP_DATA [ext/opcache/tests/jit/assign_dim_undef_op_data_008.phpt] 

@Girgias

Girgias commented Nov 23, 2026

Copy link
Copy Markdown
Member

Also an ASAN failure on PPC64:

========DIFF========
     Automatic conversion of false to array is deprecated
     Undefined variable $undef
003- int(1)
003+ =================================================================
004+ ==3497920==ERROR: AddressSanitizer: heap-use-after-free on address 0x3e6793ef87f2 at pc 0x000125ab17e0 bp 0x3fffc02b47b0 sp 0x3fffc02b4828
005+ READ of size 1 at 0x3e6793ef87f2 thread T0
006+     #0 0x125ab17dc in zend_assign_to_variable_ex /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_execute.h:195:7
007+     #1 0x125407634 in ZEND_ASSIGN_DIM_SPEC_CV_CONST_OP_DATA_CV_HANDLER /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_vm_execute.h:45641:12
008+     #2 0x1252d6788 in execute_ex /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_vm_execute.h:116352:12
009+     #3 0x1252d9ad4 in zend_execute /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_vm_execute.h:122064:2
010+     #4 0x126386fb0 in zend_execute_script /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend.c:1997:3
011+     #5 0x1244f2d64 in php_execute_script_ex /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/main/main.c:2680:13
012+     #6 0x1244f4614 in php_execute_script /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/main/main.c:2720:9
013+     #7 0x1263a1c54 in do_cli /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/sapi/cli/php_cli.c:962:5
014+     #8 0x12639af1c in main /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/sapi/cli/php_cli.c:1385:18
015+     #9 0x3fff97717000  (/usr/lib64/libc.so.6+0x27000)
016+     #10 0x3fff977172e4 in __libc_start_main (/usr/lib64/libc.so.6+0x272e4)
017+ 
018+ 0x3e6793ef87f2 is located 18 bytes inside of 136-byte region [0x3e6793ef87e0,0x3e6793ef8868)
019+ freed by thread T0 here:
020+     #0 0x11f1ed66c in free (/srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/sapi/cli/php+0x2fed66c)
021+     #1 0x124de38d0 in tracked_free /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_alloc.c:3375:2
022+     #2 0x124db4398 in _efree /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_alloc.c:2932:3
023+     #3 0x125c4d75c in zend_array_destroy /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_hash.c:2085:2
024+     #4 0x12631365c in rc_dtor_func /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_variables.c:57:2
025+     #5 0x125ab08f8 in zend_assign_to_variable /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_execute.h:183:4
026+     #6 0x1253a2bf4 in ZEND_ASSIGN_SPEC_VAR_CONST_RETVAL_UNUSED_HANDLER /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_vm_execute.h:25949:11
027+     #7 0x1252d6788 in execute_ex /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_vm_execute.h:116352:12
028+     #8 0x12524a480 in zend_call_function /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_execute_API.c:1041:3
029+     #9 0x125240ff0 in _call_user_function_impl /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_execute_API.c:820:9
030+     #10 0x12637ae40 in zend_error_zstr_at /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend.c:1598:10
031+     #11 0x12637f3f4 in zend_error_va_list /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend.c:1652:2
032+     #12 0x12637fad0 in zend_error_unchecked /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend.c:1726:2
033+     #13 0x125a96620 in zval_undefined_cv /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_execute.c:280:3
034+     #14 0x125a9fbd8 in _get_zval_ptr_cv_BP_VAR_R /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_execute.c:353:10
035+     #15 0x125407394 in ZEND_ASSIGN_DIM_SPEC_CV_CONST_OP_DATA_CV_HANDLER /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_vm_execute.h:45640:12
036+     #16 0x1252d6788 in execute_ex /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_vm_execute.h:116352:12
037+     #17 0x1252d9ad4 in zend_execute /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_vm_execute.h:122064:2
038+     #18 0x126386fb0 in zend_execute_script /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend.c:1997:3
039+     #19 0x1244f2d64 in php_execute_script_ex /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/main/main.c:2680:13
040+     #20 0x1244f4614 in php_execute_script /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/main/main.c:2720:9
041+     #21 0x1263a1c54 in do_cli /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/sapi/cli/php_cli.c:962:5
042+     #22 0x12639af1c in main /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/sapi/cli/php_cli.c:1385:18
043+     #23 0x3fff97717000  (/usr/lib64/libc.so.6+0x27000)
044+     #24 0x3fff977172e4 in __libc_start_main (/usr/lib64/libc.so.6+0x272e4)
045+ 
046+ previously allocated by thread T0 here:
047+     #0 0x11f1ed9c0 in malloc (/srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/sapi/cli/php+0x2fed9c0)
048+     #1 0x124da6038 in tracked_malloc /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_alloc.c:3350:14
049+     #2 0x124db3b84 in _emalloc /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_alloc.c:2922:10
050+     #3 0x125c00b44 in zend_hash_real_finit_packed_ex /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_hash.c:160:10
051+     #4 0x125c33e80 in _zend_hash_index_add_or_update_i /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_hash.c:1344:25
052+     #5 0x125c36190 in zend_hash_index_lookup /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_hash.c:1449:9
053+     #6 0x125a8e844 in zend_fetch_dimension_address_inner /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_execute.c:2829:4
054+     #7 0x125ab2318 in zend_fetch_dimension_address_inner_W_CONST /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_execute.c:2891:9
055+     #8 0x1254071a4 in ZEND_ASSIGN_DIM_SPEC_CV_CONST_OP_DATA_CV_HANDLER /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_vm_execute.h:45633:20
056+     #9 0x1252d6788 in execute_ex /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_vm_execute.h:116352:12
057+     #10 0x1252d9ad4 in zend_execute /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_vm_execute.h:122064:2
058+     #11 0x126386fb0 in zend_execute_script /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend.c:1997:3
059+     #12 0x1244f2d64 in php_execute_script_ex /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/main/main.c:2680:13
060+     #13 0x1244f4614 in php_execute_script /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/main/main.c:2720:9
061+     #14 0x1263a1c54 in do_cli /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/sapi/cli/php_cli.c:962:5
062+     #15 0x12639af1c in main /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/sapi/cli/php_cli.c:1385:18
063+     #16 0x3fff97717000  (/usr/lib64/libc.so.6+0x27000)
064+     #17 0x3fff977172e4 in __libc_start_main (/usr/lib64/libc.so.6+0x272e4)
065+ 
066+ SUMMARY: AddressSanitizer: heap-use-after-free /srv/actions/.cache/act/3080b9e50c85181b/hostexecutor/Zend/zend_execute.h:195:7 in zend_assign_to_variable_ex
067+ Shadow bytes around the buggy address:
068+   0x3e6793ef8500: 00 00 00 00 00 04 fa fa fa fa fa fa fa fa 00 00
069+   0x3e6793ef8580: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 fa
070+   0x3e6793ef8600: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
071+   0x3e6793ef8680: 00 00 00 00 00 00 00 00 00 fa fa fa fa fa fa fa
072+   0x3e6793ef8700: fa fa fd fd fd fd fd fd fd fd fd fd fd fd fd fd
073+ =>0x3e6793ef8780: fd fd fd fd fa fa fa fa fa fa fa fa fd fd[fd]fd
074+   0x3e6793ef8800: fd fd fd fd fd fd fd fd fd fd fd fd fd fa fa fa
075+   0x3e6793ef8880: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
076+   0x3e6793ef8900: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
077+   0x3e6793ef8980: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
078+   0x3e6793ef8a00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
079+ Shadow byte legend (one shadow byte represents 8 application bytes):
080+   Addressable:           00
081+   Partially addressable: 01 02 03 04 05 06 07 
082+   Heap left redzone:       fa
083+   Freed heap region:       fd
084+   Stack left redzone:      f1
085+   Stack mid redzone:       f2
086+   Stack right redzone:     f3
087+   Stack after return:      f5
088+   Stack use after scope:   f8
089+   Global redzone:          f9
090+   Global init order:       f6
091+   Poisoned by user:        f7
092+   Container overflow:      fc
093+   Array cookie:            ac
094+   Intra object redzone:    bb
095+   ASan internal:           fe
096+   Left alloca redzone:     ca
097+   Right alloca redzone:    cb
098+ ==3497920==ABORTING
========DONE========
FAIL JIT ASSIGN_DIM: container converted from false is overwritten while reporting undefined OP_DATA [ext/opcache/tests/jit/assign_dim_undef_op_data_008.phpt] 

@jorgsowa

Copy link
Copy Markdown
Contributor Author

It exposed issues on instances where JIT is unavailable I think. Let me check it.

arnaud-lb added a commit to bm1549/php-src that referenced this pull request Nov 24, 2026
* PHP-8.5: (25 commits)
  [skip ci] Add APP_DEBUG=0 for Symfony Preloading test
  streams: fix stale readbuflen after stream_filter_remove() on a read filter
  Update NEWS for phpGH-20920 LibreSSL build fix
  Fix phpGH-20920: do not use OPENSSL_strndup() for peer CN matching
  Simplify php_openssl_load_all_certs_from_file()
  Fix phpGH-20920: only register PKCS7_NO_DUAL_CONTENT when it is defined
  Fix phpGH-20920: guard ENGINE_cleanup() with OPENSSL_NO_ENGINE again
  ext/soap: Fix NULL dereference on empty Body with matching SOAPAction (phpGH-25661)
  ext/dom: Fix use-after-free in getElementById() after removing an ID attribute
  ext/reflection: Don't call destructor when constructor is not public in newInstance(Args)()
  ext/phar: unset() of an entry with an open handle use-after-free.
  ext/intl: Fix IntlCalendar::setTime() build on PHP 8.5 and later
  ext/intl: Reject non-finite timestamps in IntlCalendar::setTime() (php#25668)
  [skip ci] Speed up community build
  [skip ci] Backport test-suite.yml changes from master
  Fix propagation of public(set) of readonly trait property
  Make test accept different outputs
  Fix phpGH-25528: Retain the Phar OpenSSL signing key (php#25529)
  ext/pdo_sqlite: Fix use-after-free of bound string and LOB parameters
  ext/opcache: Fix JIT ASSIGN_DIM undefined OP_DATA and dim reporting on non-array containers (phpGH-24665)
  ...
@jorgsowa

Copy link
Copy Markdown
Contributor Author

Follow-up fix for this issue #25701

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.

3 participants