Skip to content

Web mode: hex view of the last dump (#85) - #88

Merged
compot-dev merged 4 commits into
mainfrom
hexview
Nov 15, 2026
Merged

compot-dev merged 4 commits into
mainfrom
hexview

Conversation

@compot-dev

Copy link
Copy Markdown
Collaborator

Part of #85: the classic hex view, web mode first.

  • Page: a "Hex view" panel under the status registers. It shows the last dump (the file of the state), 512 bytes a page. Each row has the address, 16 bytes with a gap after 8, and the ASCII. 00 and FF bytes are dim. There are Prev and Next buttons, and Go to an address in hex (0x1F000 or 1F000), aligned down to 16. Colours are the existing page tokens only: amber addresses, ink bytes, dim ASCII. The file-name plate keeps its case.
  • Server: /dumps/<file> takes Range: bytes=A-B or bytes=A-. It answers 206 with Content-Range, or 416 with Content-Range: bytes */N when A is past the end. A range past the end is cut at the end. Several ranges, a suffix range or another unit get the whole file, as before. Full responses now send Accept-Ranges: bytes. The page reads only the 512 bytes it shows, so a 512 MB dump opens at once.
  • Version 1.42.0, CHANGELOG, README (en, ru, zh-CN).

Tests:

  • New websim checks pass:
    • a 512-byte part (206, exact bytes);
    • an open range;
    • a range past the end is cut;
    • 416 from past the end;
    • several ranges give the whole file;
    • the page has the panel and the Range read.
  • Local Docker builds: native, LIBUSB=1 and musl x86_64/arm/mipsel/mips, all with 0 warnings.
  • Live on centerm-11 with a CH347T and an MX25L25635E (32 MB of random data):
    • Read, then Range: bytes=0-511 gave 206, Content-Range: bytes 0-511/33554432;
    • in headless Chromium the panel shows the same bytes as xxd of the dump (4E 86 82 4B 39 D0 C3 1A …), at 900 px and at 390 px (the table scrolls inside the panel).
  • The Prev, Next and Go buttons were not clicked in a real browser yet.

Under the status registers: address, bytes and ASCII, 16 bytes a row,
512 bytes a page, 00 and FF dim; Prev, Next and Go to an address in hex.
/dumps/<file> takes Range: bytes=A-B or A- and answers 206 with
Content-Range, 416 past the end; several ranges give the whole file, as
before. A dump of any size opens at once.

Part of #85.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Add a paged hex view for web-mode dumps

✨ Enhancement 🧪 Tests 📝 Documentation 🕐 20-40 Minutes

Grey Divider

AI Description

• Show the last dump as navigable hex and ASCII without downloading the whole file.
• Serve dump byte ranges so large files can be viewed 512 bytes at a time.
• Add range-response tests, update documentation, and bump the version to 1.42.0.
Diagram

sequenceDiagram
    actor User
    participant Page as Web page
    participant State as State API
    participant Dumps as Dump endpoint
    participant File as Dump file
    Page->>State: Poll state
    State-->>Page: Last dump filename
    User->>Page: Navigate hex view
    Page->>Dumps: GET with byte Range
    Dumps->>File: Seek and read requested bytes
    File-->>Dumps: Dump bytes
    Dumps-->>Page: 206 bytes or 416
    Page-->>User: Render hex or error
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Dedicated hex-view API
  • ➕ Could return page metadata and formatted bytes in one application-specific response.
  • ➖ Adds an endpoint and duplicates byte-serving behavior already suited to HTTP ranges.
  • ➖ Couples display formatting to the server.

Recommendation: Keep byte ranges on the existing dump endpoint: they preserve the download URL while allowing the page to fetch only what it displays. A dedicated API offers little benefit for this read-only view.

Files changed (8) +148 / -8

Enhancement (2) +106 / -7
web.cServe single byte ranges from dump files +59/-7

Serve single byte ranges from dump files

• Parses bounded and open-ended byte ranges, seeks to the requested offset, and limits the response body to that range. Returns 206 for valid ranges and 416 past the file end; unsupported or multiple ranges retain full-file behavior.

src/web.c

web_page.htmlAdd a navigable hex panel for the last dump +47/-0

Add a navigable hex panel for the last dump

• Adds a panel beneath the registers with address, byte, and ASCII columns, plus Prev, Next, and hex-address navigation. It fetches 512-byte ranges and dims 00 and FF bytes.

src/web_page.html

Tests (1) +25 / -0
websim.cCover hex-view wiring and dump range responses +25/-0

Cover hex-view wiring and dump range responses

• Checks that the served page contains the hex panel and range request. Exercises exact, open-ended, clipped, unsatisfiable, and multiple-range dump requests.

tests/websim.c

Documentation (4) +16 / -0
CHANGELOG.mdRecord the 1.42.0 hex-view release +7/-0

Record the 1.42.0 hex-view release

• Adds a release entry describing paged hex viewing and the dump endpoint’s range responses.

CHANGELOG.md

README.mdDocument hex viewing in English +3/-0

Document hex viewing in English

• Explains the last-dump display, navigation controls, and partial reads for large files.

README.md

README.ru.mdDocument hex viewing in Russian +3/-0

Document hex viewing in Russian

• Adds the hex-view feature and range-reading behavior to the Russian web-mode guide.

README.ru.md

README.zh-CN.mdDocument hex viewing in Simplified Chinese +3/-0

Document hex viewing in Simplified Chinese

• Adds the hex-view feature and range-reading behavior to the Simplified Chinese web-mode guide.

README.zh-CN.md

Other (1) +1 / -1
main.cBump the application version to 1.42.0 +1/-1

Bump the application version to 1.42.0

• Changes the version constant reported by the application.

src/main.c

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Old replies block valid hex jumps ✓ Resolved

Resolving commit: 2d6b30a

Resolution reason
N/A
Description
hexLoad() checks the request number before drawing, but updates hx.size from a 206 response and
resets hx.off on a 416 response before that check. If an older request finishes after a new dump
opens or the user changes pages, its metadata can make Go reject valid addresses or make navigation
use the wrong offset even though its bytes are not drawn.

2. A server restart leaves an obsolete dump ✓ Resolved

Resolving commit: 2d6b30a

Resolution reason
Hex requests carry a sequence number (hx.req); only the latest request's response is drawn or
reports an error, so an outstanding response cannot restore stale dump bytes. A 416 now resets the
offset. The panel is not explicitly hidden/cleared on an empty file.
Description
render() opens the hex panel for a nonempty s.file but has no path to close it when s.file
becomes empty. After a server restart, an existing page accepts the new sequence-zero state with no
file and continues showing the previous filename and bytes indefinitely.

3. Valid ranges return the whole dump ✓ Resolved
Description
dump_range() skips only spaces before bytes= and requires the endpoint to be followed
immediately by \r. A request with a tab after Range: or trailing header whitespace therefore
falls back to a 200 response that streams the entire dump instead of the requested slice.

View review recommended (4)
4. A past-end jump strands page navigation ✓ Resolved
Description
hexGo() stores an address beyond the known dump size in hx.off, while hexLoad() handles the
resulting 416 by replacing the view text without updating the navigation buttons. After that jump,
Prev can remain disabled from page zero and Next's size check refuses to run, leaving Go as the only
way back.

5. Huge jumps request the entire dump ✓ Resolved
Description
hexGo() accepts arbitrarily long hexadecimal strings, allowing parseInt() to produce Infinity or
a number whose decimal string uses exponent notation. hexLoad() then sends a nonnumeric Range
value, which dump_range() treats as no range and answers by starting a full-dump transfer instead
of a 512-byte read.

6. Some full dump requests return a slice ✓ Resolved
Description
handle() passes the first Range: match from find_header() to dump_range() without checking
for another Range field or stopping at the end of the headers. Two Range fields therefore use only
the first instead of returning the whole file, while a GET body beginning with Range: can change a
full-file response to 206 or 416 when it arrives with the headers.

7. Old dump pages overwrite the current view ✓ Resolved
Description
hexLoad() renders every completed fetch without checking whether its file and offset still match
the current hex view. If a user navigates quickly or a new read publishes another dump while a
request is pending, an older response can replace the newer page beneath the current filename and
leave the address and navigation controls out of sync.

Grey Divider

Tip of the day
💡 Did you know, you can reply 'qodo' on any finding to push back, ask questions, or dig deeper

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Each load gets a number; an answer that comes after a newer request (fast
paging, or a new dump while a part was coming) is dropped, so the bytes,
the address and the buttons stay of the same page.
@compot-dev

Copy link
Copy Markdown
Collaborator Author

Fixed in 5ad972c: Old dump pages overwrite the current view. Each hexLoad() now takes a number (hx.req). The success and error handlers draw only when that number is still the latest, so an answer that arrives after a newer request is dropped. This covers fast paging and a new dump arriving while a part is still coming. The websim page check now covers it. All tests pass. native, LIBUSB=1 and musl x86_64/arm/mipsel/mips build with 0 warnings.

@compot-dev

Copy link
Copy Markdown
Collaborator Author

/review

The Range of a dump request is looked for among the headers only, not in
bytes that came after them; a second Range header makes it the whole
file, as several ranges in one header do.
@compot-dev

Copy link
Copy Markdown
Collaborator Author

Fixed in 331b1af: Some full dump requests return a slice. handle() now uses a Range: line only when it is before the end of the headers. A second Range: header among them sends the whole file, the same as several ranges in one header. Bytes received after the headers are ignored. A new websim check covers two Range headers, which get the whole dump. All tests pass. native, LIBUSB=1 and musl x86_64/arm/mipsel/mips build with 0 warnings.

@compot-dev

Copy link
Copy Markdown
Collaborator Author

/review

…paces

Go takes up to 12 hex digits and an address below the dump size: a huge
number became 1e+20 in the Range, which the server took as no range and
sent the whole dump. Past the end nothing is asked and the last address
is told; a 416 (a dump that changed) goes back to page 0. The server
skips tabs before the range and blanks after it.
@compot-dev

Copy link
Copy Markdown
Collaborator Author

All three findings are fixed in 2d6b30a:

  1. Valid ranges return the whole dump. dump_range() now skips spaces and tabs before bytes=, and spaces and tabs after the end of the range. A new websim check sends Range:\tbytes=16-31 and gets a 206 with those 16 bytes.
  2. A past-end jump strands page navigation. Go now refuses an address at or past the known dump size and names the last address. Nothing is requested and the offset stays where it was. If a 416 still arrives (the dump changed), the view goes back to offset 0 and asks for an address inside the dump.
  3. Huge jumps request the entire dump. Go now accepts at most 12 hex digits (48 bits, well inside the safe integer range), so the Range never carries 1e+20. Together with the size check in (2), only in-range parts are requested.

All tests pass. native, LIBUSB=1 and musl x86_64/arm/mipsel/mips build with 0 warnings.

@compot-dev

Copy link
Copy Markdown
Collaborator Author

/review

@compot-dev

Copy link
Copy Markdown
Collaborator Author

Both new findings on 2d6b30a are minor edge cases of the view. They are not fixed in this PR and go into a small follow-up:

  1. Old replies block valid hex jumps. A stale 206 or 416 can still update hx.size or hx.off before the request-number check. The bytes it carries are never drawn. At worst Go refuses a valid address once, and the next Prev, Next or Go loads the right page. The fix is to move the my===hx.req check before those writes.
  2. A server restart leaves an obsolete dump. An open page keeps its last hex page after the service restarts with no dump. The fix is to hide the panel and reset hx when a state comes with no file.

Neither can write to the chip or send the whole dump: every request is still a 512-byte range inside the known size.

@compot-dev
compot-dev merged commit fd327e9 into main Nov 15, 2026
9 checks passed
@compot-dev
compot-dev deleted the hexview branch November 15, 2026 23:23
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.

1 participant