(r io.ByteReader, count uint64)
| 113 | } |
| 114 | |
| 115 | func readBool(r io.ByteReader, count uint64) ([]bool, error) { |
| 116 | if err := checkUint64(count, true); err != nil { |
| 117 | return nil, err |
| 118 | } |
| 119 | |
| 120 | // Preallocate with a maximum initial capacity of 1024 to prevent memory DoS |
| 121 | // on invalid high counts. Growth via append has negligible performance impact |
| 122 | // because 7z decompression CPU cycles dominate total execution time. |
| 123 | defined := make([]bool, 0, min(count, 1024)) |
| 124 | |
| 125 | var b, mask byte |
| 126 | for range count { |
| 127 | if mask == 0 { |
| 128 | var err error |
| 129 | |
| 130 | b, err = r.ReadByte() |
| 131 | if err != nil { |
| 132 | return nil, fmt.Errorf("readBool: ReadByte error: %w", err) |
| 133 | } |
| 134 | |
| 135 | mask = 0x80 |
| 136 | } |
| 137 | |
| 138 | defined = append(defined, (b&mask) != 0) |
| 139 | mask >>= 1 |
| 140 | } |
| 141 | |
| 142 | return defined, nil |
| 143 | } |
| 144 | |
| 145 | func readOptionalBool(r io.ByteReader, count uint64) ([]bool, error) { |
| 146 | if err := checkUint64(count, true); err != nil { |
no test coverage detected
searching dependent graphs…