Skip to content

get: ask again for a chunk that arrives with extra bytes on it - #128

Closed
bdbarnett wants to merge 1 commit into
mainfrom
fix/get-spurious-tx-bytes
Closed

bdbarnett wants to merge 1 commit into
mainfrom
fix/get-spurious-tx-bytes

Conversation

@bdbarnett

Copy link
Copy Markdown
Collaborator

A P4 DEV-KIT (ESP32-P4, native USB CDC) sometimes sends more than it printed. mpremote's fs_readfile asks for print(repr(r(256))) and parses the reply with ast.literal_eval; on this board the reply can carry, after the closing quote, the zero padding of the string's memory and sometimes the 16-byte header of the string object next to it. The header starts with 0x04, which ends the reply early. get of a 2.8 MB model failed with "source code string cannot contain null bytes" on three runs in a row (at 47 KB, 750 KB and 2.9 MB). The bytes inside the quotes were right every time.

Serial transports now read each chunk after an explicit seek, parse only the first line, check its length, and ask again after a clean return to the raw REPL prompt when it is wrong. A chunk that never comes right fails with the byte offset.

cli/tests/test_read_file_checked.py feeds the reader a board that appends zeros, appends the object header with its 0x04, and cuts a reply short. mpremote's own fs_readfile fails the first of these with the same "null bytes" error.

mpremote reads a file 256 bytes at a time as print(repr(r(256))) and parses
the line with ast.literal_eval. A P4 DEV-KIT on its native USB sometimes sends
more than it printed: after the closing quote come the zero padding of the
string's memory and, now and then, the 16-byte header of the string object
next to it (a type pointer, hash, length and data pointer), whose first byte
is 0x04 and ends the reply early. Reading a 2.8 MB model failed that way on
three runs out of three ("source code string cannot contain null bytes", and
once with the reply framing lost), at 47 KB, 750 KB and 2.9 MB, with the board
running nothing else. The bytes inside the quotes were right each time.

Serial transports now read a file with an explicit seek per chunk, parse only
the first line, check the length, and read the chunk again (after a clean
return to the raw REPL prompt) when it is wrong.
@bdbarnett

Copy link
Copy Markdown
Collaborator Author

Reopened from a branch with a corrected commit message.

@bdbarnett bdbarnett closed this Oct 21, 2026
@bdbarnett
bdbarnett deleted the fix/get-spurious-tx-bytes branch October 21, 2026 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant