Skip to content

editor: bound the edit buffer (fix typing/paste overflow and unreloadable max-size saves) - #610

Open
vinej wants to merge 1 commit into
jkotlinski:masterfrom
vinej:fix/editor-buffer-overflow
Open

editor: bound the edit buffer (fix typing/paste overflow and unreloadable max-size saves)#610
vinej wants to merge 1 commit into
jkotlinski:masterfrom
vinej:fix/editor-buffer-overflow

Conversation

@vinej

@vinej vinej commented Jul 14, 2026

Copy link
Copy Markdown

Hi — thanks for durexForth! While using the v editor I hit two related buffer-size bugs and have a small fix for forth/v.fs. Sharing in case it's useful upstream.

1. The edit buffer had no upper bound while editing

ins-char and paste-line grew eof with no check against the end of the text buffer. Only loading a file was size-checked, not typing or pasting. Once eof passed $cbff, it marched into $cc00+ (hi-res color RAM, then $d000 I/O registers), silently corrupting memory — which shows up as forth crashing "after a while," and more readily with larger files.

Fix: a small room? guard so ins-char/paste-line refuse (and show F in the status line) instead of overrunning:

: room? ( n -- f ) eof @ + bufend 1+ u< ;

2. Save and load disagreed on the maximum size

The load path rejects files over 44 blocks (here $20 + @ #44 >). But a buffer filled all the way to $cbff saves as 45 blocks:

  • content = $cbff - $a001 = 11262 bytes → file = 11264 bytes (+2 load address) → ceil(11264/254) = 45 blocks.

So you could fill and save a buffer that the editor then refused to re-open with "too big".

Fix: cap bufend to $cba7, so a maximally-full buffer stays within the same 44-block reloadable limit:

  • content = $cba7 - $a001 = 11174 bytes → file = 11176 bytes = 44*254 → exactly 44 blocks.

$cba7 is also still below $cc00, so it satisfies both the physical and the reloadable limit (the smaller one wins).

Testing

Verified against stock VICE 3.9:

  • With the guard, eof clamps at the limit and nothing is written past the buffer into $cc00.
  • A maximally-filled buffer now both saves and re-opens (previously "too big" on re-open).
  • Existing 44-block files (e.g. gfx) still load and display correctly.

The change is confined to forth/v.fs (+29/-1, mostly explanatory comments). Happy to adjust naming/comments or split it if you'd prefer.

The V editor grew its text buffer with no upper bound while typing or
pasting: ins-char and paste-line advanced eof past the buffer end
($cbff) into $cc00+ (gfx color RAM, then $d000 I/O registers), silently
corrupting memory and crashing forth after a while with larger files.
Only file LOADING was size-checked, not editing.

Add a `room?` guard so ins-char and paste-line refuse (showing "F" in the
status line) instead of overrunning.

Also make save and load agree on the maximum size. The load path rejects
files over 44 disk blocks, but a buffer filled to $cbff saves as 45
blocks -- so a maxed-out buffer could be saved and then refused on
re-open with "too big". Cap bufend to $cba7 (11174 content bytes) so a
full buffer always saves within the 44-block reloadable limit.

Verified against stock VICE 3.9: eof clamps at the limit with no write
past the buffer, and a maximally-filled buffer saves and re-opens.
@Whammo

Whammo commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Acknowledged.
This is better than a nod to not use big files. ☺️

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