Conversation
copy_emacs_string used a too-small buffer as a size query. Emacs 31 signals memory-buffer-too-small in that case (module_copy_string_contents), so the error escaped when the retry path did not clear it. Ask for the size with a NULL buffer instead, which is the documented query form on all versions. Also reserve the uint64_t-rounded size: strtolower rewrites the string in 8-byte chunks and touches up to 7 bytes past the null-terminator, which could cross the end of a bump block. calc_cost returned c[m - 1] with m unsigned, so an empty needle indexed c[UINT_MAX] and crashed. An empty needle matches everything at no cost.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
hotfuzz-module.chas three defects incopy_emacs_stringandcalc_cost. Thefirst makes the module unusable on Emacs 31; the other two are latent on every
version.
copy_emacs_stringused an undersized buffer as a size queryThe old code passed the remaining tail of the current bump block to
copy_string_contentsto discover the string's length, treating a failure withlen != origlenas "too small, retry bigger".That is not a supported size query. Emacs 31's
module_copy_string_contentssignals
memory-buffer-too-smallwhen the supplied buffer is short, and theretry path only cleared the non-local exit on one of the two failure branches —
so on a short block the error escaped into Lisp and filtering died with
Older versions don't signal, but they also don't reliably report the required
size when the shortfall is detected early, so the retry could allocate from a
stale
len.The documented query form is a
NULLbuffer, which is what this patch uses. Thecopy then happens exactly once, into a block known to be large enough.
The bump reservation didn't cover
strtolower's overwritestrtolowerrewrites the string inuint64_t-sized chunks, so it touches up toalignof(uint64_t) - 1bytes past the null-terminator. The allocation onlyrounded up in the
capacity < lenbranch; the opportunistic in-place pathadvanced
cursorpast the aligned end without having checked that those byteswere inside the block. A string landing near a block boundary could therefore be
written past
limit.This patch rounds the required size up front and uses that rounded value both to
test whether the string fits and to advance the cursor.
calc_costindexedc[UINT_MAX]on an empty needlecalc_costreturnsc[m - 1]withmunsigned. For an empty needlemis 0,so it read
c[UINT_MAX]. An empty needle matches everything at no cost, whichis now returned directly.
Notes for the maintainer
computation are untouched.
copy_emacs_stringdrops the opportunistic"copy first, measure on failure" path in favor of one query plus one copy.
That is one extra
copy_string_contentscall per string, and it removes thegoto success/non_local_exit_clearcontrol flow.