runtime: check for overflow when growing slices and concatenating strings
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
- #6189 di @davecheney — chiusa senza merge
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 55/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- go, wasm
- Ambito
- backend, embedded-iot
Direzione di ricerca
Start by reading runtime.sliceGrow and runtime.stringConcat, then trace how they calculate capacities, lengths, and allocation sizes. Reproduce the slice case with the supplied program on a 32-bit target; add coverage for capacity and allocation overflow, plus string length overflow. Done when capacities and allocation sizes stay within int limits and oversized concatenations are rejected.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
runtime.sliceGrow and runtime.stringConcat do not check their size calculations. On 32-bit targets, these calculations can produce lengths or capacities that do not fit in an int, or allocation sizes that wrap around.
For strings and slices with non-zero-sized elements, the issue is unlikely on 64-bit targets because the required allocations exceed the typical 48-bit address space. Slices of zero-sized elements are an exception: they can reach the capacity limit without a large allocation.
Slice growth
sliceGrow rounds the requested capacity up to the next power of two. On a 32-bit target, a request for a capacity of 1 << 30 is rounded up to 1 << 31, which does not fit in an int. The allocation size can also wrap around when the capacity is multiplied by the element size, resulting in an allocation that is too small.
This program reproduces the capacity error without a large allocation:
package main
func main() {
n := int(^uint(0)>>2) + 1
s := make([]struct{}, n)
s = append(s, struct{}{})
println(len(s), cap(s))
}
On a 32-bit target, tinygo run -target=wasm main.go prints:
1073741825 -2147483648
The capacity is negative, but it should be at least the length. The same program also produces a negative capacity on a 64-bit target.
String concatenation
stringConcat adds the lengths of its arguments without checking the result. On a 32-bit target, concatenating two strings of 1 GiB each can produce a length of 1 << 31, which does not fit in an int.
Expected behavior
sliceGrow should keep capacities within the range of int and check the allocation size for overflow. stringConcat should reject a result whose length does not fit in an int.
- Lingua principale
- Go
- Stelle
- 17.8k
- Fork
- 1.1k
- Merge medio
- 1g 4h
- PR unite (30g)
- 380
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di tinygo-org/tinygo
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
tinygo-org/tinygo#6727 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
tinygo-org/tinygo#6711 ·
I maintainer di solito rispondono entro 1 giorno
-
Builds are not reproducible: cgo snippet paths in debug infoForse già presa @tridev-tej l’ha presa 1 giorno fa. Apertaenhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
tinygo-org/tinygo#6619 ·
I maintainer di solito rispondono entro 1 giorno
-
Fix the targets that tinygo build -target rejectsForse già presa @narguis l’ha presa 2 giorni fa. Apertabug good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
tinygo-org/tinygo#6617 · 5 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
tinygo-org/tinygo#6312 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di tinygo-org/tinygo
Issue simili
-
release
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
github/gh-aw-mcpg#17603 ·
I maintainer di solito rispondono entro 1 giorno
-
help wanted
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 94/100
oras-project/oras-go#1827 ·
I maintainer di solito rispondono entro 1 giorno
-
docs: database/sql Sessions example never commits its batch, and its "Full Example" link is a 404Apertadocumentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
ClickHouse/clickhouse-go#2185 ·
I maintainer di solito rispondono entro 1 giorno
-
bug needs triage receiver/podman
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
open-telemetry/opentelemetry-collector-contrib#53700 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
tagvalue.Read fails with "token too long" on lines over 64 KiBForse già presa @G26karthik l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
spdx/tools-golang#319 ·