Skip to content

COMPRESS-734: Write all bytes when a channel writes only part of a buffer - #845

Open
Marti2203 wants to merge 1 commit into
apache:masterfrom
Marti2203:sevenz-partial-channel-write
Open

Marti2203 wants to merge 1 commit into
apache:masterfrom
Marti2203:sevenz-partial-channel-write

Conversation

@Marti2203

Copy link
Copy Markdown

Fixes COMPRESS-734.

SevenZOutputFile ignored the return value of SeekableByteChannel.write(ByteBuffer) at all five write sites, while still counting every byte in the CRC and fileBytesWritten. A channel that writes fewer bytes than are remaining, which the WritableByteChannel contract allows, therefore produced a corrupt archive without any error. This adds a writeFully loop, the same as ZipIoUtil.writeAll for ZIP, and uses it for every write.

SevenZOutputFileTest.testPartialChannelWrites writes through a channel that accepts at most 1 KiB per call and reads the archive back: without the change reading fails with "packSize (100,100) is out of range"; with it the content matches. SevenZOutputFileTest (36 tests) and mvn -B -DskipTests -DskipITs pass.

This issue was found by an LLM-Enhanced Static Analysis Engine and verified manually. The patch and this description were prepared with AI assistance (Claude Code) and reviewed by me; the commit carries an Assisted-By: trailer.

…ffer

SevenZOutputFile ignored the return value of SeekableByteChannel.write
and counted every byte as written, so a channel that writes fewer bytes
than requested produced a corrupt archive without an error. Loop until
the buffer is written, as ZipIoUtil.writeAll does for ZIP.

Assisted-By: Claude Code:claude-opus-5-5
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