Skip to content

fix: validate key length (ErrKeyTooLong) and fix uint16 header overflow - #448

Merged
janisz merged 1 commit into
allegro:mainfrom
mazkev:fix/bigcache-improvements-v2
Nov 27, 2026
Merged

janisz merged 1 commit into
allegro:mainfrom
mazkev:fix/bigcache-improvements-v2

Conversation

@mazkev

@mazkev mazkev commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR is part 1 of splitting #448 as requested: it validates key lengths against maxKeyLength (65,535 bytes) and fixes a uint16 header addition overflow in encoding.go.

Key Changes

  • Defined maxKeyLength = 1<<16 - 1 and ErrKeyTooLong.
  • Added key length checks in BigCache (Get, GetWithInfo, Set, Append, Delete) and cacheShard (get, getWithInfo, set, append).
  • Cast binary.LittleEndian.Uint16(...) to int in readEntry and readKeyFromEntry before adding headersSizeInBytes to prevent uint16 wraparound panics for keys >= 65518 bytes.
  • Added TestBigCache_KeyTooLong.

@janisz

janisz commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Can you split it into 5 separated or stacked PRs?

@mazkev
mazkev force-pushed the fix/bigcache-improvements-v2 branch from 9119a2d to 9c2fce9 Compare November 27, 2026 02:05
@mazkev mazkev changed the title fix: validate key length, prevent iterator stack overflow, and fix in teger overflows fix: validate key length (ErrKeyTooLong) and fix uint16 header overflow Nov 27, 2026
@mazkev

mazkev commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Sure thing @janisz! I've split #448 into 5 independent PRs targeting main:

  1. fix: validate key length (ErrKeyTooLong) and fix uint16 header overflow #448 — Key length validation (ErrKeyTooLong) and uint16 header overflow fix
  2. fix(iterator): prevent stack overflow in SetNext and protect Value with mutex #450 — Prevent stack overflow in EntryInfoIterator.SetNext and protect Value() with mutex
  3. fix: guard against integer overflow in BytesQueue growth and convertMBToBytes #451 — Integer overflow guards in BytesQueue.allocateAdditionalMemory and convertMBToBytes
  4. fix(server): return on HTTP 500 errors and handle 405 Method Not Allowed #452 — Return on HTTP 500 errors and handle 405 Method Not Allowed in server handlers
  5. fix(bigcache): use configured clock.Epoch() in background cleanUp ticker #453 — Use configured cache.clock.Epoch() in background cleanUp ticker

@janisz
janisz merged commit a3fb90f into allegro:main Nov 27, 2026
2 checks 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.

2 participants