Skip to content

internal/stream: reject sizes below one tag in EncryptedChunkCount#696

Closed
sweis wants to merge 1 commit intoFiloSottile:mainfrom
sweis:claude/fix-stream-negative-size-HXoHp
Closed

internal/stream: reject sizes below one tag in EncryptedChunkCount#696
sweis wants to merge 1 commit intoFiloSottile:mainfrom
sweis:claude/fix-stream-negative-size-HXoHp

Conversation

@sweis
Copy link
Contributor

@sweis sweis commented Mar 12, 2026

EncryptedChunkCount returned (0, nil) for negative or sub-tag-size inputs —
the consistency check rounds both sides to 0 and passes silently. This would
cascade into NewDecryptReaderAt computing finalChunkIndex = -1.

Fix: a valid payload always carries at least one Poly1305 tag, even for empty
plaintext. Reject anything smaller than chacha20poly1305.Overhead up front.

Test: go test ./internal/stream/ -run TestEncryptedChunkCountRejectsSmallSizes -v

@sweis sweis closed this Mar 19, 2026
@sweis sweis reopened this Mar 19, 2026
@FiloSottile
Copy link
Owner

This looks just wrong: I get invalid encrypted payload size: 0 and invalid encrypted payload size: 15 from the current code, not nil.

@sweis sweis closed this Mar 22, 2026
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