Skip to content

Fix panic in From<io::Error> implementation for frame::Error#221

Merged
PSeitz merged 1 commit into
PSeitz:mainfrom
phoerious:fix/from-ioerr-impl
May 9, 2026
Merged

Fix panic in From<io::Error> implementation for frame::Error#221
PSeitz merged 1 commit into
PSeitz:mainfrom
phoerious:fix/from-ioerr-impl

Conversation

@phoerious
Copy link
Copy Markdown
Contributor

@phoerious phoerious commented May 8, 2026

The From implementation for converting an io::Error to a frame::Error always panics for custom IO errors.

This is the current implementation:

impl From<io::Error> for Error {
    fn from(e: io::Error) -> Self {
        match e.get_ref().map(|e| e.downcast_ref::<Error>()) {
            Some(_) => *e.into_inner().unwrap().downcast::<Error>().unwrap(),
            None => Error::IoError(e),
        }
    }
}

This will always panic on the last unwrap() for any kind of custom IO error that is not a wrapped frame::Error, regardless of whether e.downcast_ref::<Error>() actually succeeded.

I changed the map() call to and_then(), which is probably the originally intended behaviour.

Found this bug while testing error propagation in my own LZ4 stream wrapper implementation, which uses lz4_flex as a backend.

phoerious added a commit to chatnoir-eu/chatnoir-resiliparse that referenced this pull request May 8, 2026
@PSeitz PSeitz merged commit 1756d13 into PSeitz:main May 9, 2026
2 checks passed
@PSeitz
Copy link
Copy Markdown
Owner

PSeitz commented May 9, 2026

Thanks for the fix!

@PSeitz
Copy link
Copy Markdown
Owner

PSeitz commented May 9, 2026

released in 0.13.1

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.

2 participants