Skip to content

Commit 83ffb3c

Browse files
jackcclaude
andcommitted
Validate multirange element count against source length before allocating
A crafted binary multirange with a large element count could trigger an excessive allocation in SetLen before the per-element parsing would detect the short source. Validate that the count is plausible given the available data. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent 828f214 commit 83ffb3c

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎pgtype/multirange.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ func (c *MultirangeCodec) decodeBinary(m *Map, multirangeOID uint32, src []byte,
210210
elementCount := int(binary.BigEndian.Uint32(src[rp:]))
211211
rp += 4
212212

213+
// Each element requires at least 4 bytes for its length prefix.
214+
if elementCount > len(src)/4 {
215+
return fmt.Errorf("multirange element count %d exceeds available data", elementCount)
216+
}
217+
213218
err := multirange.SetLen(elementCount)
214219
if err != nil {
215220
return err

0 commit comments

Comments
 (0)