Fix illegal memory access while moving gap#19
Merged
jserv merged 2 commits intoOct 10, 2025
Conversation
When operations are: open new file -> insert one character -> arrow left -> insert one character -> arrow right -> insert one character -> insert one character. Above cause segmentation fault for undo_clear_redo function executes undo_node_t *node = stack->current->next; the source of problem: gap_ptr return gb->egap+(pos-front_size) when pos is located at [text after gap]. As the result, dest in gap_move also points to [text after gap]. If computes len = dest - gap, will easily cause unecessay move for byte after ebuffer. For example, if dest points to first byte of text after gap, and memory layout is [text before gap][gap][text after gap] -> [1 byte][64Kib-2][1 byte] then len = 64Kib-1. Causing illegal memory access after egap. test: this commit pass the test.
jserv
requested changes
Oct 9, 2025
jserv
left a comment
Owner
There was a problem hiding this comment.
Improve the test suite accordingly.
jserv
reviewed
Oct 9, 2025
jserv
reviewed
Oct 9, 2025
990792f to
818bf6c
Compare
Owner
|
Thank @Max042004 for contributing! |
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.
When operations are: open new file -> insert one character -> arrow left -> insert one character ->
arrow right -> insert one character -> insert one character. Above cause segmentation fault for undo_clear_redo function executes undo_node_t *node = stack->current->next;
the source of problem:
gap_ptr return gb->egap+(pos-front_size) when pos is located at [text after gap]. As the result, dest in gap_move also points to [text after gap]. If computes len = dest - gap, will easily cause unecessay move for byte after ebuffer.
For example, if dest points to first byte of text after gap, and memory layout is [text before gap][gap][text after gap] -> [1 byte][64Kib-2][1 byte] then len = 64Kib-1. Causing illegal memory access after egap.
test:
this commit pass the test.