Skip to content

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

Merged
bdbarnett merged 1 commit into
mainfrom
fix/get-extra-tx-bytes
Oct 21, 2026
Merged

bdbarnett merged 1 commit into
mainfrom
fix/get-extra-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 every run. The bytes inside the quotes were right each 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
every run ("source code string cannot contain null bytes"; the instrumented
runs failed 47 KB and 750 KB in, and one printed loop without the model
failed the same way), 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
bdbarnett merged commit cbcaea2 into main Oct 21, 2026
4 checks passed
@bdbarnett
bdbarnett deleted the fix/get-extra-tx-bytes branch October 21, 2026 19:46
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