Skip to content

Fix unbounded buffer growth in aead_decrypt chunk reassembly#3023

Merged
madeye merged 1 commit intomasterfrom
fix/aead-decrypt-chunk-compaction
Feb 9, 2026
Merged

Fix unbounded buffer growth in aead_decrypt chunk reassembly#3023
madeye merged 1 commit intomasterfrom
fix/aead-decrypt-chunk-compaction

Conversation

@madeye
Copy link
Contributor

@madeye madeye commented Feb 9, 2026

Summary

  • The idx-tracking optimization in aead_decrypt (from 31731ba) skipped memmove when partial AEAD chunks spanned multiple calls, but never compacted the dead space before idx
  • This caused the chunk buffer to grow proportionally to total data transferred (~10 MB growth per 10 MB), tripping the stress test memory leak threshold on macOS CI
  • Fix: compact residual data to the front when appending new ciphertext, keeping the buffer bounded

Server RSS before/after (10 MB transfer):

Cipher Before fix After fix
aes-128-gcm 8.4 → 18.7 MB (+10.3 MB) 2.5 → 3.1 MB (+0.6 MB)
aes-256-gcm 8.2 → 14.4 MB (+6.2 MB) 2.5 → 3.2 MB (+0.7 MB)
chacha20-ietf-poly1305 8.1 → 18.5 MB (+10.3 MB) 2.5 → 3.2 MB (+0.7 MB)

Test plan

  • Unit tests pass (ctest --output-on-failure)
  • Stress test passes locally (python3 tests/stress_test.py --bin build/shared/bin/ --size 10)
  • CI passes on ubuntu-latest and macos-latest

🤖 Generated with Claude Code

The idx-tracking optimization in aead_decrypt skipped memmove when
partial AEAD chunks spanned multiple calls, but never compacted the
dead space before idx. This caused the chunk buffer to grow
proportionally to total data transferred (~10 MB growth per 10 MB
transferred), tripping the stress test memory leak threshold.

Compact residual data to the front when appending new ciphertext,
keeping the buffer bounded to the size of the residual plus new data.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@madeye madeye merged commit 2981f65 into master Feb 9, 2026
2 checks passed
@madeye madeye deleted the fix/aead-decrypt-chunk-compaction branch February 9, 2026 01:17
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