Clamp the int-to-int32 limit conversions at the State Store boundary #1327

Closed
opened 2026-10-27 13:39:57 +00:00 by sam · 0 comments
Owner

Goal

Every limit or offset that reaches a sqlc int32 parameter is clamped the way
internal/infrastructure/postgres/store.go:704 already clamps TaskPage.

Evidence

internal/gateway/session_store_postgres.go:488, internal/infrastructure/postgres/events.go:66,75,142,
internal/infrastructure/postgres/steps.go:69 and internal/infrastructure/postgres/access.go:219 convert a
caller-supplied int straight to int32. A value past math.MaxInt32 wraps negative
and Postgres rejects the query with "LIMIT must not be negative". gosec G115
flags each conversion.

Stop when

[ ] Each conversion clamps at its boundary, or takes a value already bounded there.
[ ] A limit past the bound returns the deep page rather than a query error.

Close reason

Events, TokensByDay and ListDenials clamp at the boundary; gateway search limit is already capped and step depth is bounded by MaxCallDepth


Imported from beads archie-core-g14d · GitHub #1555 · type task · priority P2 · created 2026-10-08 · closed 2026-10-13

## Goal Every limit or offset that reaches a sqlc int32 parameter is clamped the way internal/infrastructure/postgres/store.go:704 already clamps TaskPage. ## Evidence internal/gateway/session_store_postgres.go:488, internal/infrastructure/postgres/events.go:66,75,142, internal/infrastructure/postgres/steps.go:69 and internal/infrastructure/postgres/access.go:219 convert a caller-supplied int straight to int32. A value past math.MaxInt32 wraps negative and Postgres rejects the query with "LIMIT must not be negative". gosec G115 flags each conversion. ## Stop when [ ] Each conversion clamps at its boundary, or takes a value already bounded there. [ ] A limit past the bound returns the deep page rather than a query error. ### Close reason Events, TokensByDay and ListDenials clamp at the boundary; gateway search limit is already capped and step depth is bounded by MaxCallDepth --- _Imported from beads `archie-core-g14d` · GitHub #1555 · type task · priority P2 · created 2026-10-08 · closed 2026-10-13_
sam added the mediumtask labels 2026-10-27 13:39:57 +00:00
sam self-assigned this 2026-10-27 13:39:57 +00:00
sam closed this issue 2026-10-27 13:39:57 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sam/archie#1327