Language: Go
Label: vulnerable
CWE: CWE-1284 \u2014 Improper Validation of Specified Quantity in Input
The product receives input that is expected to specify a quantity (such as size or length), but it does not validate or incorrectly validates that the quantity has the required properties.

Code:
func FromBytes(size int, bits []byte) Bitfield {
	bf := NewBitfield(size)
	start := len(bf) - len(bits)
	if start < 0 {
		panic("bitfield too small")
	}
	copy(bf[start:], bits)
	return bf
}