Skip to content

lore: return an error on a malformed IPC message header#16

Open
glitch-ux wants to merge 1 commit into
EpicGames:mainfrom
glitch-ux:fix/ipc-header-panic
Open

lore: return an error on a malformed IPC message header#16
glitch-ux wants to merge 1 commit into
EpicGames:mainfrom
glitch-ux:fix/ipc-header-panic

Conversation

@glitch-ux

Copy link
Copy Markdown

What

Make blocking_read_v1_message return a recoverable error on a malformed V1 IPC
message header instead of panicking, and add a regression test.

Why

blocking_read_v1_message (lore/src/remote/message.rs) reads the 5-byte V1
header off the local IPC socket (the lore CLI ↔ local lore service) and
unwrapped the parsed header:

let header = V1Header::from_bytes(&header_bytes).unwrap();

V1Header::from_bytes returns Err(MessageError) for a header whose
serialization-type byte isn't a known value, but the caller .unwrap()s it, so
a corrupted/partial frame — or a version-mismatched local service — panics the
process instead of surfacing that descriptive error. The enclosing function
already returns Result<Option<(V1Header, Message)>, MessageError> and every
other read in it uses ?, so the recoverable path already exists; the
.unwrap() simply bypassed it.

Fixes #15.

How

V1Header::from_bytes(&header_bytes).unwrap()V1Header::from_bytes(&header_bytes)?.
The error type already matches MessageError, so no mapping is needed — the
descriptive error ("Message received with invalid serialization type: …") now
reaches the caller. No public API, wire-protocol, or on-disk-format change.

Testing

  • Added errors_on_invalid_serialization_type_in_header to
    lore/tests/remote_message.rs: it feeds a header with an invalid
    serialization-type byte (0xff) through blocking_read_v1_message and asserts
    it returns Err. Before this change that path panics at the unwrap.
  • cargo test -p lore --test remote_message → 3 passed.
  • cargo clippy -p lore --all-targets -- -D warnings --no-deps → clean.
  • cargo +nightly fmt --all --check → clean.
  • pre-commit file hooks (end-of-file-fixer, trailing-whitespace, codespell, …) → pass.

AI assistance

This change was prepared with the help of an AI coding assistant (Claude Code),
in keeping with the project's AI assistance policy. The diff was built and
verified locally as shown in Testing, and is submitted under my
responsibility.

blocking_read_v1_message read the 5-byte V1 header off the local IPC
socket and unwrapped V1Header::from_bytes, panicking when the header's
serialization-type byte was not a known value. The enclosing function
already returns Result<_, MessageError> and from_bytes produces a
descriptive error, so propagate it with `?` instead of panicking.

Add a regression test that drives a header with an invalid
serialization-type byte through blocking_read_v1_message and asserts it
returns an error.

Fixes EpicGames#15

Signed-off-by: glitch-ux <glitch-ux@users.noreply.github.com>
@mjansson

mjansson commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Makes sense, but please avoid adding extra // SPDX-FileCopyrightText: 2026 glitch-ux stamping in the file headers.

The PR intake process will do proper user attribution in the Lore revision that will result from this being applied - the revision will carry information that you submitted this change.

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.

lore CLI panics on a malformed IPC message header instead of returning an error

2 participants