Skip to content

Use common function for TypeError on illegal offset access#10544

Merged
Girgias merged 6 commits into
php:masterfrom
Girgias:offset-common-error-func
Jun 6, 2023
Merged

Use common function for TypeError on illegal offset access#10544
Girgias merged 6 commits into
php:masterfrom
Girgias:offset-common-error-func

Conversation

@Girgias

@Girgias Girgias commented Feb 8, 2023

Copy link
Copy Markdown
Member

Follow-up on #10504

This also fixes some consistency issues

Currently, using CI to check the JIT changes are correct as I am getting weird errors (possibly due to ASAN/UBSAN)

@Girgias

Girgias commented Feb 8, 2023

Copy link
Copy Markdown
Member Author

Would like to get opinions on the approach of using the BP_VAR_* constants.

Also, I've just used BP_VAR_R to get the default message, but my usages are probably wrong.

Opinions @arnaud-lb, @iluuu1994, @derickr ?

@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.

I'm always in favor of improving error messages. It seems like this will be somewhat inconsistent though as some of these functions aren't aware of the BP and can be used for any of them, but propagating it just for the error message doesn't seem worth it.

Comment thread ext/spl/spl_array.c Outdated
Comment thread ext/spl/spl_array.c Outdated
Comment thread ext/opcache/jit/zend_jit_helpers.c Outdated
Comment thread ext/opcache/jit/zend_jit_helpers.c Outdated
Comment thread ext/opcache/jit/zend_jit_helpers.c Outdated
Comment thread ext/opcache/jit/zend_jit_helpers.c Outdated
Comment thread Zend/zend_vm_def.h Outdated
Comment thread Zend/zend_execute.c Outdated
Comment thread Zend/zend_execute.c Outdated
@Girgias
Girgias force-pushed the offset-common-error-func branch from f0d0e33 to 93e78d4 Compare February 9, 2023 15:16
Comment thread Zend/tests/bug24773.phpt Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think this case shows we probably should improve the message somewhat. As this is inconsistent with trying to unset the offset of a string (which is banned in general). Maybe strings do need to be seperate :/

@Girgias
Girgias force-pushed the offset-common-error-func branch from 93e78d4 to 1d35b17 Compare May 31, 2023 15:11
@Girgias
Girgias requested review from bukka and dstogov as code owners May 31, 2023 15:11
@Girgias
Girgias requested a review from iluuu1994 May 31, 2023 15:17

@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.

I didn't go through all the changes this time because it doesn't seem the BPs have changed.

Comment thread Zend/zend.c Outdated
Comment thread ext/spl/spl_fixedarray.c Outdated

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.

To be fully correct this would need to get the class name passed from the caller.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I know, but that requires some more intrusive changes, which I want to do as a follow-up. As I first notices this being an issue with the ArrayObject case. But I think in both cases some places have hard coded the value of the class name.

Comment thread Zend/zend_execute.c Outdated

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.

You replace the calls to specialized functions with the calls to a single universal one. This requires sending more arguments and therefore will increases the VM code size.

@arnaud-lb arnaud-lb 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.

Looks good to me appart from other comments

Comment thread Zend/tests/036.phpt Outdated

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.

Only a question, not a suggestion: What do you think of also specifying what is allowed? Array offset must be int or string, cannot access offset of type Closure

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We can only really do this for arrays and strings :/ as objects that implement ArrayOffset can in theory support any type

@dstogov dstogov 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.

I suggest to split ``zend_illegal_container_offset() back to cheaper specialized functions at least for the VM handlers.

Girgias added 3 commits June 5, 2023 15:14
This merges all usages of emiting an offset TypeError into a new ZEND_API function
zend_illegal_container_offset(const char* container, const zval *offset, int type);

Where the container should represent the type on which the access is attempted (e.g. string, array)
The offset zval that is used, where the error message will display its type
The type of access, which should be a BP_VAR_* constant, to get special message for isset/empty/unset
@Girgias
Girgias force-pushed the offset-common-error-func branch from 1d35b17 to 381e865 Compare June 5, 2023 14:37
@Girgias

Girgias commented Jun 5, 2023

Copy link
Copy Markdown
Member Author

I suggest to split ``zend_illegal_container_offset() back to cheaper specialized functions at least for the VM handlers.

I hope what I've done is what you asked, should I do the same for the JIT VM handlers?

@Girgias
Girgias force-pushed the offset-common-error-func branch from 381e865 to c41efe0 Compare June 5, 2023 15:34

@dstogov dstogov 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.

In this state, the patch shouldn't make any harm, but I also don't see any benefits.
I'm indifferent.

@Girgias
Girgias merged commit 99fa740 into php:master Jun 6, 2023
@Girgias
Girgias deleted the offset-common-error-func branch June 6, 2023 10:28
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.

4 participants