Skip to content

id(libsql): decode chunked HTTP bodies as bytes before UTF-8 conversion #8504

Closed

Description

@dezren39

Evidence

pkgs/id/src/foreign_libsql.rs:833-849 converts the entire raw HTTP response using String::from_utf8_lossy before removing chunk framing. dechunk then interprets the HTTP chunk size (a byte count) as a Rust string slice boundary at lines 856-873. The production transport calls this parser at line 765.

A valid chunked response can split the UTF-8 bytes of é across two one-byte chunks: 1\r\n\xc3\r\n1\r\n\xa9\r\n0\r\n\r\n. The lossy conversion replaces each incomplete byte sequence with a multi-byte replacement character; slicing it at byte 1 panics. Even where it does not panic, converting before reassembly can corrupt valid UTF-8. A remote response can therefore interrupt the operation rather than returning its data or a transport error.

Acceptance criteria

  • Parse and validate chunk framing using byte slices, concatenate chunk payload bytes, and only then decode the assembled body according to the transport contract.
  • Valid UTF-8 split across chunk boundaries round-trips without corruption or panic; cover this with a regression test.
  • Malformed or truncated framing returns a transport error rather than panicking, with focused tests.
  • Preserve correct handling of ordinary chunked and non-chunked responses.

Activity

  1. developing-today commented on Nov 11, 2026

    @developing-today
    Contributor
  2. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · triaged + picked up (inline triage)

    • Agent: repo-worker-code (queue task 14865, lane code-n)
    • Session: Muse scheduled lane N, 2026-11-11T03:54Z
    • Triage: work kind task/small-fix; priority priority/normal (a remote chunked response can panic the transport or corrupt valid UTF-8); effort effort/s (one function pair + regression tests in pkgs/id/src/foreign_libsql.rs); kind kind/bug.
    • Verified: parse_http_response lossy-converts the whole raw response to a string before dechunking, and dechunk slices that string at the chunk size (a byte count) — a multi-byte UTF-8 sequence split across chunks panics or corrupts, exactly as filed (pkgs/id/src/foreign_libsql.rs:833-873 on main).
    • First concrete step: rewrite framing on byte slices — split head/body as bytes, dechunk into assembled bytes, decode UTF-8 only after assembly — with regression tests for the split-é chunk pair, malformed/truncated framing (error, never panic), and ordinary chunked + non-chunked responses.
    • Acceptance check: the tests above pass in cargo test -p id foreign_libsql and no panic path remains in the chunk parser.
  3. added
    kind/bug
    task/small-fix
    priority/normal
    effort/s
    queue/claimed
    status/in-progress
    work/assigned
    on Nov 11, 2026
  4. added a commit that references this issue on Nov 11, 2026
  5. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done (triaged inline, fixed + merged)

    • Agent: repo-worker-code (queue task 14865, lane code-n)
    • Session: Muse scheduled lane N, 2026-11-11T04:05Z
    • Outcome: PR fix(id): decode chunked HTTP bodies as bytes before UTF-8 conversion (#8504) #8515 MERGED (merge commit fb220a7); this issue auto-closed by the PR.
    • Fix: byte-first chunk parsing in pkgs/id/src/foreign_libsql.rs — head/body split on raw bytes, dechunk(&[u8]) -> Vec<u8> concatenates payload bytes untouched, UTF-8 is decoded (lossy, the prior body contract) only after assembly. Malformed/truncated framing returns the existing transport errors; no string slicing at byte counts remains.
    • Verification: the new split-UTF8 regression test panicked on the unpatched code at foreign_libsql.rs:871 (end byte index 1 is not a char boundary); post-fix cargo test -p id --lib foreign_libsql — 21 passed / 0 failed; changed hunks rustfmt-clean. Codex review was still running when the PR merged under standing merge authority (no findings posted at merge time); any late Codex finding on PR fix(id): decode chunked HTTP bodies as bytes before UTF-8 conversion (#8504) #8515 should be fixed forward on main.
  6. removed
    status/in-progress
    queue/claimed
    work/assigned
    on Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/skind/bugpriority/normalstatus:donetask/small-fix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions