Skip to content

Fix illegal memory access while moving gap#19

Merged
jserv merged 2 commits into
jserv:masterfrom
Max042004:fix/bug-gap_move-illegal-memory-access
Oct 10, 2025
Merged

Fix illegal memory access while moving gap#19
jserv merged 2 commits into
jserv:masterfrom
Max042004:fix/bug-gap_move-illegal-memory-access

Conversation

@Max042004

Copy link
Copy Markdown
Contributor

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.

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 jserv left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Improve the test suite accordingly.

Comment thread tests/test-file_operations.sh Outdated
Comment thread tests/test-file_operations.sh Outdated
@Max042004 Max042004 force-pushed the fix/bug-gap_move-illegal-memory-access branch from 990792f to 818bf6c Compare October 10, 2025 03:45
@jserv jserv merged commit bc14c6f into jserv:master Oct 10, 2025
4 checks passed
@jserv

jserv commented Oct 10, 2025

Copy link
Copy Markdown
Owner

Thank @Max042004 for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants