Skip to content

memory: bound segment growth to prevent makeslice panic on malformed program - #702

Open
ipezygj wants to merge 1 commit into
NethermindEth:mainfrom
ipezygj:bound-segment-size-panic
Open

memory: bound segment growth to prevent makeslice panic on malformed program#702
ipezygj wants to merge 1 commit into
NethermindEth:mainfrom
ipezygj:bound-segment-size-panic

Conversation

@ipezygj

@ipezygj ipezygj commented Jul 19, 2026

Copy link
Copy Markdown

Problem

Segment.Read/Write grow a segment to fit an offset via IncreaseSegmentSize(offset + 1), which does make([]MemoryValue, newSize) with an unbounded, program-controlled size. A program that reads or writes a huge memory offset makes the Go runtime panic with makeslice: len out of range, which crashes the process — there is no recover() in the VM/runner.

Repro (a program whose bytecode reads offset 0x80000000000001):

panic: runtime error: makeslice: len out of range
  ...IncreaseSegmentSize (pkg/vm/memory/memory.go:160)
  ...Segment.Read (pkg/vm/memory/memory.go:122)
  ...RunStep -> RunUntilPc -> Run

Fix

Reject an offset beyond a generous maxSegmentSize with a clean error in Read/Write, so a malformed program returns an error instead of crashing the host. The limit is intentionally generous (no legitimate execution approaches it) and commented as tunable to the intended memory model.

  • make([]MemoryValue, huge) panic → graceful error.
  • Adds TestSegmentReadWriteHugeOffsetReturnsError.
  • No regression: go test ./pkg/vm/memory/ passes; the repro program now returns memory offset ... exceeds max segment size instead of panicking.

…program

Segment.Read/Write grow the segment to fit an offset via IncreaseSegmentSize(offset+1), which
calls make([]MemoryValue, newSize) with an unbounded, program-controlled size. A program that
reads/writes a huge memory offset (e.g. offset 0x80000000000001) makes the runtime panic with
'makeslice: len out of range', crashing the process — there is no recover() in the VM. Reject
offsets beyond a generous maxSegmentSize with a clean error instead. Adds a regression test.
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