Repository navigation
Stop reading a dBASE III memo at its end-of-memo marker - #350
Merged
Merged
Conversation
DbfMemoDbase3.BuildMemo kept reading blocks while the trimmed block was shorter than 512 characters, so with NUL padded blocks it ran on through the following memos. Each memo then pulled in hundreds of megabytes, making reads extremely slow and memory hungry, and a memo that filled its first block was cut at 512 characters. Read raw blocks until the first 0x1A (or NUL, or the end of the file) and decode the bytes once. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
This was referenced Nov 24, 2026
Closed
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.



Fixes #349
Problem
DbfMemoDbase3.BuildMemohad its stop condition inverted: it stopped when a trimmed block was 512 characters or more and carried on when it was shorter.ReadStringtrims NULs and spaces, so in a memo file that pads blocks with NULs almost every block comes back short, and the loop read on through the following memos. The0x1Aend-of-memo marker was never checked.On the file from the issue (1.8 GB DBF, 2.3 GB DBT, four memo columns) the first memo came back as 322 million characters; the real memos average 112 bytes.
Fix
Read raw 512 byte blocks into a reused buffer, stop at the first
0x1A(or NUL, or the end of the file), decode once, then trim surrounding spaces as before.Behaviour changes
dbase_83was affected and had no test).0x1Amarkers or text from following memos.Tests
New
DbfMemoDbase3Tests(18 cases, 16 fail on main) using synthetic memo streams and the existingdbase_83fixture: NUL, stale-data and space padding, memos ending either side of a block boundary, a multi-byte character split across blocks, missing marker, and end of file. The reporter's files are not included.🤖 Generated with Claude Code