Reads brotli stream header and parses "window bits". @param s initialized state, before any read is performed. @return -1 if header is invalid
(State s)
| 228 | * @return -1 if header is invalid |
| 229 | */ |
| 230 | private static int decodeWindowBits(State s) { |
| 231 | /* Change the meaning of flag. Before that step it means "decoder must be capable of reading |
| 232 | * "large-window" brotli stream. After this step it means that "large-window" feature |
| 233 | * is actually detected. Despite the window size could be same as before (lgwin = 10..24), |
| 234 | * encoded distances are allowed to be much greater, thus bigger dictionary could be used. */ |
| 235 | final int largeWindowEnabled = s.isLargeWindow; |
| 236 | s.isLargeWindow = 0; |
| 237 | |
| 238 | BitReader.fillBitWindow(s); |
| 239 | if (BitReader.readFewBits(s, 1) == 0) { |
| 240 | return 16; |
| 241 | } |
| 242 | int n = BitReader.readFewBits(s, 3); |
| 243 | if (n != 0) { |
| 244 | return 17 + n; |
| 245 | } |
| 246 | n = BitReader.readFewBits(s, 3); |
| 247 | if (n != 0) { |
| 248 | if (n == 1) { |
| 249 | if (largeWindowEnabled == 0) { |
| 250 | /* Reserved value in regular brotli stream. */ |
| 251 | return -1; |
| 252 | } |
| 253 | s.isLargeWindow = 1; |
| 254 | /* Check "reserved" bit for future (post-large-window) extensions. */ |
| 255 | if (BitReader.readFewBits(s, 1) == 1) { |
| 256 | return -1; |
| 257 | } |
| 258 | n = BitReader.readFewBits(s, 6); |
| 259 | if (n < MIN_LARGE_WINDOW_BITS || n > MAX_LARGE_WINDOW_BITS) { |
| 260 | /* Encoded window bits value is too small or too big. */ |
| 261 | return -1; |
| 262 | } |
| 263 | return n; |
| 264 | } |
| 265 | return 8 + n; |
| 266 | } |
| 267 | return 17; |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * Switch decoder to "eager" mode. |
no test coverage detected