apps/tinypad: fix select all delete crash (fix #173) #700

Merged
Leency merged 3 commits from tinypad-select-all-delete-crash into main 2026-09-23 20:19:18 +00:00
Contributor

fixes both issues in #173

fixes both issues in https://git.kolibrios.org/KolibriOS/kolibrios/issues/173
CODEOWNERS rules requested review from system 2026-09-18 00:34:30 +00:00
Leency requested review from apps 2026-09-18 00:34:57 +00:00
Leency requested review from Developers 2026-09-18 00:34:59 +00:00
Burer changed title from Tinypad select all delete crash to apps/tinypad: fix select all delete crash (fix #173) 2026-09-18 07:24:36 +00:00
Burer requested changes 2026-09-18 08:02:33 +00:00
Dismissed
Burer left a comment
Owner

1. editor_realloc_lines failure is indistinguishable from success.
.failed returns eax = 0, but 0 is also a valid delta whenever mem.ReAlloc returns the same address. None of the nine call sites checks it, and line_add_spaces (tp-common.asm:367) does add esi,eax and then writes through esi into a buffer that was not grown - silent heap corruption where before there was an immediate crash. Signal failure with CF and make callers bail.

2. 16 -> 18 is right, but not for the stated reason.
EDITOR_LINE_DATA is 6 bytes, not 8 (dd + dw; struct.inc:123 adds no padding), so a line costs 16 plus text and the old constant was correct. The actual gap was the terminator slot, which the new add ebx,sizeof.EDITOR_LINE_DATA supplies. 18 just over-reserves 2 bytes per line.

3. key.ctrl_y (tp-key.asm:744) is the one remaining Lines.Count decrement without a terminator restore.
It survives - it never reads the terminator's Size and its rep movsd carries it along - but if set_lines_terminator is the invariant, apply it there too.

Nit: set_lines_terminator leaves the terminator's Flags as garbage.

**1. `editor_realloc_lines` failure is indistinguishable from success.** `.failed` returns `eax = 0`, but 0 is also a valid delta whenever `mem.ReAlloc` returns the same address. None of the nine call sites checks it, and `line_add_spaces` (tp-common.asm:367) does `add esi,eax` and then writes through `esi` into a buffer that was not grown - silent heap corruption where before there was an immediate crash. Signal failure with CF and make callers bail. **2. 16 -> 18 is right, but not for the stated reason.** `EDITOR_LINE_DATA` is 6 bytes, not 8 (`dd` + `dw`; struct.inc:123 adds no padding), so a line costs 16 plus text and the old constant was correct. The actual gap was the terminator slot, which the new `add ebx,sizeof.EDITOR_LINE_DATA` supplies. 18 just over-reserves 2 bytes per line. **3. `key.ctrl_y` (tp-key.asm:744) is the one remaining `Lines.Count` decrement without a terminator restore.** It survives - it never reads the terminator's `Size` and its `rep movsd` carries it along - but if `set_lines_terminator` is the invariant, apply it there too. Nit: `set_lines_terminator` leaves the terminator's `Flags` as garbage.
Burer approved these changes 2026-09-18 08:46:40 +00:00
IgorA approved these changes 2026-09-23 19:35:34 +00:00
Leency added 3 commits 2026-09-23 20:17:08 +00:00
The lines buffer is terminated by a line header with zero Size, but
Lines.Size was computed as 16 bytes per line plus the file length, while
a line actually takes 8 bytes of header, the text and 10 trailing
spaces. It matched only because line separators are not stored, so the
terminator ended up outside of Lines.Size.

delete_selection moves the tail of the buffer up to Lines+Lines.Size, so
the terminator was not carried over and its new place kept garbage from
the deleted text. That garbage was then read as the next line Size,
editor_realloc_lines asked for a huge block, mcall 68.20 returned 0 and
cur_editor.Lines became null: reading at address 0 gave EAX=554E454D and
a page fault in get_real_length.

Reserve the worst case in load_from_memory, restore the terminator after
the line count decreases, and keep the old buffer when the realloc fails.

Assisted-by: Claude Opus 5 <noreply@anthropic.com>
Assisted-by: Claude Opus 5 <noreply@anthropic.com>
tinypad: handle lines buffer realloc failure, review fixes
Test PR / Build (en_US) (pull_request) Successful in 1m48s
Test PR / Build (es_ES) (pull_request) Successful in 1m57s
Test PR / Build (ru_RU) (pull_request) Successful in 2m1s
fc31e8ee54
editor_realloc_lines now reports failure with CF, and the callers that
grow the buffer bail out instead of writing into a buffer that was not
grown. line_add_spaces passes the failure on.

EDITOR_LINE_DATA is 6 bytes, so 16 bytes per line was already enough;
only the terminator slot was missing. Restore the terminator in
key.ctrl_y as well and clear its Flags.

Assisted-by: Claude Opus 5 <noreply@anthropic.com>
Leency force-pushed tinypad-select-all-delete-crash from f6c21afd9e to fc31e8ee54 2026-09-23 20:17:08 +00:00 Compare
Leency scheduled this pull request to auto merge when all checks succeed 2026-09-23 20:17:20 +00:00
Leency merged commit 298155191d into main 2026-09-23 20:19:18 +00:00
Leency deleted branch tinypad-select-all-delete-crash 2026-09-23 20:19:18 +00:00
Sign in to join this conversation.
No Reviewers
KolibriOS/system
No labels
3 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: KolibriOS/kolibrios#700