Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

index out of range panic #11

Closed
Closed
@dvyukov

Description

@dvyukov

The following program crashes with a panic:

package main

import "github.com/golang/snappy/snappy"

func main() {
    data := []byte("\xff\xff\xff\xff\xff\xff\xff\xff\xec0")
    n, err := snappy.DecodedLen(data)
    if err != nil || n > 1e6 {
        return
    }
    dec, err := snappy.Decode(nil, data)
    if err != nil {
        if dec != nil {
            panic("dec is not nil")
        }
        return
    }
    if len(dec) != n {
        println(len(dec), n)
        panic("bad decoded len")
    }
    n = snappy.MaxEncodedLen(len(dec))
    enc, err := snappy.Encode(nil, dec)
    if err != nil {
        panic(err)
    }
    if len(enc) > n {
        panic("bad encoded len")
    }
}
panic: runtime error: index out of range

goroutine 1 [running]:
github.com/golang/snappy/snappy.Decode(0x0, 0x0, 0x0, 0xc208041f00, 0xa, 0x20, 0x0, 0x0, 0x0, 0x0, ...)
    src/github.com/golang/snappy/snappy/decode.go:54 +0xaca
main.main()
    snappy.go:11 +0xf6

on commit 156a073

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions