Skip to content

LZ4FrameInputStream throws NullPointerException on streams that contain only skippable frames #103

Closed

Description

@yawkat

skippableFrame() sets firstFrameHeaderRead = true (line 175), but buffer and frameInfo stay null. After a stream made only of skippable frames:

  • the first read() returns -1;
  • a second read(), skip() or available() then throws NullPointerException: Cannot invoke "java.nio.ByteBuffer.remaining()" because "this.buffer" is null (~328).

The same happens with readSingleFrame=true, and when getExpectedContentSize() / isExpectedContentSizeDefined() is called before read(). The shortest trigger is 8 bytes: a skippable magic plus size 0.

The existing testSkippableOnly calls read() only once, which is why it passes.

Fix: split the flag in two.

  • Add private boolean anyFrameRead; and use it in nextFrameInfo() for the "clean EOF vs premature end of stream" decision.
  • skippableFrame() sets anyFrameRead = true, and readHeader() sets both flags.
  • firstFrameHeaderRead then means "a real header has been read", so buffer and frameInfo are always non-null when it is true.

Extend testSkippableOnly with a second read() and an available() assertion.

See also #39 / #45 (earlier available() NPEs).

Activity

  1. self-assigned this
    on Sep 25, 2026
  2. added
    bug
    on Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions