Commit d36c398
committed
backup: M5-3 reject non-power-of-two partition_count at load (coderabbit Major #929)
partitionForGroup masks with (PartitionCount - 1) which assumes
PartitionCount is a power of two. The live adapter validator
(adapter/sqs_partitioning.go:isPowerOfTwo) enforces this for newly-
created queues, but a malformed dump like partition_count=3 would
pass readQueueMeta as-is and then hash inconsistently: (h & 0b10)
masks bit 2 only, so partition 1 is unreachable and message routing
breaks.
Fix: in readQueueMeta, after the format_version check, fail closed
on (pub.PartitionCount > 1 && PartitionCount & (PartitionCount-1)
!= 0) with ErrSQSEncodeInvalidQueue. Caught at load time so the
operator sees the invalid dump before any record is staged.
Caller audit: readQueueMeta is the single source of meta values for
the encoder pipeline. The new gate fires before encodeQueue's
addQueueMeta, validatePartitioning, and stageMessageRecords - none
of which need to repeat the check.
Regression tests:
- TestSQSEncodeRejectsNonPowerOfTwoPartitionCount: 3/5/6/7/9/10 all
fail closed.
- TestSQSEncodeAcceptsPowerOfTwoPartitionCount: 2/4/8/16/32 all
pass.1 parent 8ff0af4 commit d36c398
2 files changed
Lines changed: 57 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
624 | 624 | | |
625 | 625 | | |
626 | 626 | | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
627 | 637 | | |
628 | 638 | | |
629 | 639 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
373 | 374 | | |
374 | 375 | | |
375 | 376 | | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
376 | 423 | | |
377 | 424 | | |
378 | 425 | | |
| |||
0 commit comments