Skip to content

SkipShieldingInputStream: do not assume buffer is never read#1125

Merged
ArneBab merged 1 commit intohyphanet:nextfrom
bertm:fix/skip-crosstalk
Feb 15, 2026
Merged

SkipShieldingInputStream: do not assume buffer is never read#1125
ArneBab merged 1 commit intohyphanet:nextfrom
bertm:fix/skip-crosstalk

Conversation

@bertm
Copy link
Copy Markdown
Contributor

@bertm bertm commented Feb 15, 2026

The SkipShieldingInputStream used a shared buffer under the assumption that its contents are only written to, and are never read. However, some stream wrappers (hashing, cryptography) perform read-after-write on the buffers they are provided.

When multiple threads skip(...) concurrently this can cause data from different unrelated streams to interfere with the other streams.

Allocate a fresh buffer for every skip to prevent crosstalk between threads.

The SkipShieldingInputStream used a shared buffer under the assumption
that its contents are only written to, and are never read. However, some
stream wrappers (hashing, cryptography) perform read-after-write on the
buffers they are provided.

When multiple threads skip(...) concurrently this can cause data from
different unrelated streams to interfere with the other streams.

Allocate a fresh buffer for every skip to prevent crosstalk between
threads.
@bertm
Copy link
Copy Markdown
Contributor Author

bertm commented Feb 15, 2026

Alternatively we could change SkipShieldingInputStream to not assume that the buffers it is passed are safe for read-then-write and defensively copy their contents. In that case we need to change PaddedEphemerallyEncryptedInputStream similarly, and potentially other stream implementations too.

@Bombe
Copy link
Copy Markdown
Contributor

Bombe commented Feb 15, 2026

Very nice catch!

@ArneBab ArneBab merged commit a61ef06 into hyphanet:next Feb 15, 2026
1 check passed
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.

3 participants