Repository navigation
mbstring: save the write offset before reallocating - #25570
realFlowControl wants to merge 2 commits into
Conversation
|
@realFlowControl Thanks for this contribution. Do you think that a comment similar to |
|
@alexdowad depends on the "future reader". |
|
@alexdowad I found a way, but it involves ASan and it finds more undefined behavior like this. I'll work on adding this check in a follow up PR if that is fine for you, WDYT? |
|
Dear @realFlowControl, strictly speaking, you are right that the answer to "what comments will benefit a future human reader" is "it depends on the reader". However, my personal judgement is that a short explanatory comment here would help many human readers. (What gcc and clang see is a different issue and not related to my comment.) Ideas for how to check for UB issues in CI are certainly welcome. But I think that adding such checks to CI relates to more than just mbstring; any other part of PHP might have UB which would be good to avoid. So I would suggest discussing such ideas on the mailing list, with the target of possibly applying them to the entire codebase. (I hope this doesn't result in a flood of thousands of patches 😅) |
2706eec to
2de0ffd
Compare
|
Added the comment. Good point on the CI checks! |
|
I'm busy at this moment but will merge this as soon as I have some time. If you are a committer, please feel free to go ahead and merge if you get to it first. |
|
@realFlowControl, your other commit 23970fa got merged first, and it conflicts with this one. Can you rebase? |
When
mb_convert_buf_ensure()grows the conversion buffer, it calculates the write offset by subtracting two pointers into the old buffer after callingsafe_ferealloc(). If the allocation moves, those pointers are no longer valid. Subtracting them is undefined behavior even though neither is dereferenced.This PR saves the offset before reallocating, then add it to the new buffer’s base address.