brotli 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e39135e3c6e289c1b4f233d8e0bec31f1cfb6be48f63280b5a7609965b88459
4
- data.tar.gz: 5f0bae9eb2e35baf822e7eff9e8432e24043893afe29c70506050d41c073bbaa
3
+ metadata.gz: 05ff932639bf540d1187af86b6fedc95bbda8bbdfecee33631a6d8fb279c3c4f
4
+ data.tar.gz: d5041a8558bddb2935739372f95fa2c3a145155ac7fa1c0482f01048b20489ab
5
5
  SHA512:
6
- metadata.gz: 46ae27522c3cb015279531a8d6b91af3afcd40a0b61c552db76e7caa9562a547f8f4e2f09873f5e113314cbc0ffe811fcfdc9a0c02b84aa2df4ade1d005857e9
7
- data.tar.gz: cc393196d928f8d761b83bf7f04415c7f1ddd1b2f113008063e9b99615004adf00af95171932d009efeeb0e6ad2f5edb3c26196610475b08a4e5db0d56e5e201
6
+ metadata.gz: 3f4cb09e9781d26a84bc7395a599f4ae5978c590aa67e7ecb56699d20e5a0834851d14330a09cad9213c42e42bd1c31ee387a030882da60835c788777f77ec69
7
+ data.tar.gz: 89156626b80f23ff447e51fd903f1b94e63952a1fa6ed9b53b08272287a6c22ca40f81e1f17155a242a28da9739a07f2c4b7fa4a8305807870abb8e2d6d6a0e9
@@ -106,7 +106,9 @@ def system_brotli_available?
106
106
  have_header("brotli/shared_dictionary.h") &&
107
107
  have_func("BrotliEncoderPrepareDictionary", "brotli/encode.h") &&
108
108
  have_func("BrotliEncoderAttachPreparedDictionary", "brotli/encode.h") &&
109
- have_func("BrotliDecoderAttachDictionary", "brotli/decode.h")
109
+ have_func("BrotliDecoderAttachDictionary", "brotli/decode.h") &&
110
+ # CVE-2026-111497: patched decoders (1.2.1+, or distro backports) define this error code.
111
+ have_const("BROTLI_DECODER_ERROR_FORMAT_BLOCK_SWITCH", "brotli/decode.h")
110
112
 
111
113
  restore_mkmf_flags(flags) unless available
112
114
  available
@@ -1,3 +1,3 @@
1
1
  module Brotli
2
- VERSION = '0.9.0'
2
+ VERSION = '0.9.1'
3
3
  end
@@ -19,7 +19,7 @@
19
19
 
20
20
  #define BROTLI_VERSION_MAJOR 1
21
21
  #define BROTLI_VERSION_MINOR 2
22
- #define BROTLI_VERSION_PATCH 0
22
+ #define BROTLI_VERSION_PATCH 1
23
23
 
24
24
  #define BROTLI_VERSION BROTLI_MAKE_HEX_VERSION( \
25
25
  BROTLI_VERSION_MAJOR, BROTLI_VERSION_MINOR, BROTLI_VERSION_PATCH)
@@ -33,7 +33,7 @@
33
33
  */
34
34
 
35
35
  #define BROTLI_ABI_CURRENT 3
36
- #define BROTLI_ABI_REVISION 0
36
+ #define BROTLI_ABI_REVISION 1
37
37
  #define BROTLI_ABI_AGE 2
38
38
 
39
39
  #if BROTLI_VERSION_MAJOR != (BROTLI_ABI_CURRENT - BROTLI_ABI_AGE)
@@ -1176,7 +1176,7 @@ static BrotliDecoderErrorCode DecodeContextMap(brotli_reg_t context_map_size,
1176
1176
 
1177
1177
  /* Decodes a command or literal and updates block type ring-buffer.
1178
1178
  Reads 3..54 bits. */
1179
- static BROTLI_INLINE BROTLI_BOOL DecodeBlockTypeAndLength(
1179
+ static BROTLI_INLINE BrotliDecoderErrorCode DecodeBlockTypeAndLength(
1180
1180
  int safe, BrotliDecoderState* s, int tree_type) {
1181
1181
  brotli_reg_t max_block_type = s->num_block_types[tree_type];
1182
1182
  const HuffmanCode* type_tree = &s->block_type_trees[
@@ -1187,7 +1187,7 @@ static BROTLI_INLINE BROTLI_BOOL DecodeBlockTypeAndLength(
1187
1187
  brotli_reg_t* ringbuffer = &s->block_type_rb[tree_type * 2];
1188
1188
  brotli_reg_t block_type;
1189
1189
  if (max_block_type <= 1) {
1190
- return BROTLI_FALSE;
1190
+ return BROTLI_DECODER_ERROR_FORMAT_BLOCK_SWITCH;
1191
1191
  }
1192
1192
 
1193
1193
  /* Read 0..15 + 3..39 bits. */
@@ -1197,11 +1197,13 @@ static BROTLI_INLINE BROTLI_BOOL DecodeBlockTypeAndLength(
1197
1197
  } else {
1198
1198
  BrotliBitReaderState memento;
1199
1199
  BrotliBitReaderSaveState(br, &memento);
1200
- if (!SafeReadSymbol(type_tree, br, &block_type)) return BROTLI_FALSE;
1200
+ if (!SafeReadSymbol(type_tree, br, &block_type)) {
1201
+ return BROTLI_DECODER_NEEDS_MORE_INPUT;
1202
+ }
1201
1203
  if (!SafeReadBlockLength(s, &s->block_length[tree_type], len_tree, br)) {
1202
1204
  s->substate_read_block_length = BROTLI_STATE_READ_BLOCK_LENGTH_NONE;
1203
1205
  BrotliBitReaderRestoreState(br, &memento);
1204
- return BROTLI_FALSE;
1206
+ return BROTLI_DECODER_NEEDS_MORE_INPUT;
1205
1207
  }
1206
1208
  }
1207
1209
 
@@ -1217,7 +1219,7 @@ static BROTLI_INLINE BROTLI_BOOL DecodeBlockTypeAndLength(
1217
1219
  }
1218
1220
  ringbuffer[0] = ringbuffer[1];
1219
1221
  ringbuffer[1] = block_type;
1220
- return BROTLI_TRUE;
1222
+ return BROTLI_DECODER_SUCCESS;
1221
1223
  }
1222
1224
 
1223
1225
  static BROTLI_INLINE void DetectTrivialLiteralBlockTypes(
@@ -1254,62 +1256,68 @@ static BROTLI_INLINE void PrepareLiteralDecoding(BrotliDecoderState* s) {
1254
1256
 
1255
1257
  /* Decodes the block type and updates the state for literal context.
1256
1258
  Reads 3..54 bits. */
1257
- static BROTLI_INLINE BROTLI_BOOL DecodeLiteralBlockSwitchInternal(
1259
+ static BROTLI_INLINE BrotliDecoderErrorCode DecodeLiteralBlockSwitchInternal(
1258
1260
  int safe, BrotliDecoderState* s) {
1259
- if (!DecodeBlockTypeAndLength(safe, s, 0)) {
1260
- return BROTLI_FALSE;
1261
+ BrotliDecoderErrorCode result = DecodeBlockTypeAndLength(safe, s, 0);
1262
+ if (result != BROTLI_DECODER_SUCCESS) {
1263
+ return result;
1261
1264
  }
1262
1265
  PrepareLiteralDecoding(s);
1263
- return BROTLI_TRUE;
1266
+ return BROTLI_DECODER_SUCCESS;
1264
1267
  }
1265
1268
 
1266
- static void BROTLI_NOINLINE DecodeLiteralBlockSwitch(BrotliDecoderState* s) {
1267
- DecodeLiteralBlockSwitchInternal(0, s);
1269
+ static BROTLI_NOINLINE BrotliDecoderErrorCode
1270
+ DecodeLiteralBlockSwitch(BrotliDecoderState* s) {
1271
+ return DecodeLiteralBlockSwitchInternal(0, s);
1268
1272
  }
1269
1273
 
1270
- static BROTLI_BOOL BROTLI_NOINLINE SafeDecodeLiteralBlockSwitch(
1274
+ static BROTLI_NOINLINE BrotliDecoderErrorCode SafeDecodeLiteralBlockSwitch(
1271
1275
  BrotliDecoderState* s) {
1272
1276
  return DecodeLiteralBlockSwitchInternal(1, s);
1273
1277
  }
1274
1278
 
1275
1279
  /* Block switch for insert/copy length.
1276
1280
  Reads 3..54 bits. */
1277
- static BROTLI_INLINE BROTLI_BOOL DecodeCommandBlockSwitchInternal(
1281
+ static BROTLI_INLINE BrotliDecoderErrorCode DecodeCommandBlockSwitchInternal(
1278
1282
  int safe, BrotliDecoderState* s) {
1279
- if (!DecodeBlockTypeAndLength(safe, s, 1)) {
1280
- return BROTLI_FALSE;
1283
+ BrotliDecoderErrorCode result = DecodeBlockTypeAndLength(safe, s, 1);
1284
+ if (result != BROTLI_DECODER_SUCCESS) {
1285
+ return result;
1281
1286
  }
1282
1287
  s->htree_command = s->insert_copy_hgroup.htrees[s->block_type_rb[3]];
1283
- return BROTLI_TRUE;
1288
+ return BROTLI_DECODER_SUCCESS;
1284
1289
  }
1285
1290
 
1286
- static void BROTLI_NOINLINE DecodeCommandBlockSwitch(BrotliDecoderState* s) {
1287
- DecodeCommandBlockSwitchInternal(0, s);
1291
+ static BROTLI_NOINLINE BrotliDecoderErrorCode
1292
+ DecodeCommandBlockSwitch(BrotliDecoderState* s) {
1293
+ return DecodeCommandBlockSwitchInternal(0, s);
1288
1294
  }
1289
1295
 
1290
- static BROTLI_BOOL BROTLI_NOINLINE SafeDecodeCommandBlockSwitch(
1291
- BrotliDecoderState* s) {
1296
+ static BROTLI_NOINLINE BrotliDecoderErrorCode
1297
+ SafeDecodeCommandBlockSwitch(BrotliDecoderState* s) {
1292
1298
  return DecodeCommandBlockSwitchInternal(1, s);
1293
1299
  }
1294
1300
 
1295
1301
  /* Block switch for distance codes.
1296
1302
  Reads 3..54 bits. */
1297
- static BROTLI_INLINE BROTLI_BOOL DecodeDistanceBlockSwitchInternal(
1303
+ static BROTLI_INLINE BrotliDecoderErrorCode DecodeDistanceBlockSwitchInternal(
1298
1304
  int safe, BrotliDecoderState* s) {
1299
- if (!DecodeBlockTypeAndLength(safe, s, 2)) {
1300
- return BROTLI_FALSE;
1305
+ BrotliDecoderErrorCode result = DecodeBlockTypeAndLength(safe, s, 2);
1306
+ if (result != BROTLI_DECODER_SUCCESS) {
1307
+ return result;
1301
1308
  }
1302
1309
  s->dist_context_map_slice = s->dist_context_map +
1303
1310
  (s->block_type_rb[5] << BROTLI_DISTANCE_CONTEXT_BITS);
1304
1311
  s->dist_htree_index = s->dist_context_map_slice[s->distance_context];
1305
- return BROTLI_TRUE;
1312
+ return BROTLI_DECODER_SUCCESS;
1306
1313
  }
1307
1314
 
1308
- static void BROTLI_NOINLINE DecodeDistanceBlockSwitch(BrotliDecoderState* s) {
1309
- DecodeDistanceBlockSwitchInternal(0, s);
1315
+ static BROTLI_NOINLINE BrotliDecoderErrorCode
1316
+ DecodeDistanceBlockSwitch(BrotliDecoderState* s) {
1317
+ return DecodeDistanceBlockSwitchInternal(0, s);
1310
1318
  }
1311
1319
 
1312
- static BROTLI_BOOL BROTLI_NOINLINE SafeDecodeDistanceBlockSwitch(
1320
+ static BROTLI_NOINLINE BrotliDecoderErrorCode SafeDecodeDistanceBlockSwitch(
1313
1321
  BrotliDecoderState* s) {
1314
1322
  return DecodeDistanceBlockSwitchInternal(1, s);
1315
1323
  }
@@ -1940,6 +1948,9 @@ static BROTLI_INLINE BROTLI_BOOL CheckInputAmount(
1940
1948
  return BrotliCheckInputAmount(br);
1941
1949
  }
1942
1950
 
1951
+ /* NB: METHOD should return BROTLI_FALSE only in case there is not enough input;
1952
+ in case of "unsafe" execution, when input is guaranteed to be sufficient,
1953
+ result is ignored. */
1943
1954
  #define BROTLI_SAFE(METHOD) \
1944
1955
  { \
1945
1956
  if (safe) { \
@@ -1952,6 +1963,22 @@ static BROTLI_INLINE BROTLI_BOOL CheckInputAmount(
1952
1963
  } \
1953
1964
  }
1954
1965
 
1966
+ /* NB: METHOD should return BROTLI_DECODER_SUCCESS, BROTLI_DECODER_ERROR_*, or
1967
+ BROTLI_DECODER_NEEDS_MORE_INPUT; the later two break the processing. */
1968
+ #define BROTLI_SAFE_WITH_STATUS(METHOD) \
1969
+ { \
1970
+ BrotliDecoderErrorCode status; \
1971
+ if (safe) { \
1972
+ status = Safe##METHOD; \
1973
+ } else { \
1974
+ status = METHOD; \
1975
+ } \
1976
+ if (status != BROTLI_DECODER_SUCCESS) { \
1977
+ result = status; \
1978
+ goto saveStateAndReturn; \
1979
+ } \
1980
+ }
1981
+
1955
1982
  static BROTLI_INLINE BrotliDecoderErrorCode ProcessCommandsInternal(
1956
1983
  int safe, BrotliDecoderState* s) {
1957
1984
  int pos = s->pos;
@@ -1991,7 +2018,7 @@ CommandBegin:
1991
2018
  goto saveStateAndReturn;
1992
2019
  }
1993
2020
  if (BROTLI_PREDICT_FALSE(s->block_length[1] == 0)) {
1994
- BROTLI_SAFE(DecodeCommandBlockSwitch(s));
2021
+ BROTLI_SAFE_WITH_STATUS(DecodeCommandBlockSwitch(s));
1995
2022
  goto CommandBegin;
1996
2023
  }
1997
2024
  /* Read the insert/copy length in the command. */
@@ -2136,7 +2163,7 @@ CommandPostDecodeLiterals:
2136
2163
  } else {
2137
2164
  /* Read distance code in the command, unless it was implicitly zero. */
2138
2165
  if (BROTLI_PREDICT_FALSE(s->block_length[2] == 0)) {
2139
- BROTLI_SAFE(DecodeDistanceBlockSwitch(s));
2166
+ BROTLI_SAFE_WITH_STATUS(DecodeDistanceBlockSwitch(s));
2140
2167
  }
2141
2168
  BROTLI_SAFE(ReadDistance(s, br));
2142
2169
  }
@@ -2330,7 +2357,7 @@ CommandPostWrapCopy:
2330
2357
  }
2331
2358
 
2332
2359
  NextLiteralBlock:
2333
- BROTLI_SAFE(DecodeLiteralBlockSwitch(s));
2360
+ BROTLI_SAFE_WITH_STATUS(DecodeLiteralBlockSwitch(s));
2334
2361
  goto CommandInner;
2335
2362
 
2336
2363
  saveStateAndReturn:
@@ -2552,6 +2579,8 @@ BrotliDecoderResult BrotliDecoderDecompressStream(
2552
2579
  if (result != BROTLI_DECODER_SUCCESS) {
2553
2580
  break;
2554
2581
  }
2582
+ BROTLI_DCHECK(s->meta_block_remaining_len <=
2583
+ (int)BROTLI_BLOCK_SIZE_CAP);
2555
2584
  BROTLI_LOG_UINT(s->is_last_metablock);
2556
2585
  BROTLI_LOG_UINT(s->meta_block_remaining_len);
2557
2586
  BROTLI_LOG_UINT(s->is_metadata);
@@ -85,9 +85,7 @@ typedef enum {
85
85
  BROTLI_ERROR_CODE(_ERROR_FORMAT_, PADDING_1, -14) SEPARATOR \
86
86
  BROTLI_ERROR_CODE(_ERROR_FORMAT_, PADDING_2, -15) SEPARATOR \
87
87
  BROTLI_ERROR_CODE(_ERROR_FORMAT_, DISTANCE, -16) SEPARATOR \
88
- \
89
- /* -17 code is reserved */ \
90
- \
88
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, BLOCK_SWITCH, -17) SEPARATOR \
91
89
  BROTLI_ERROR_CODE(_ERROR_, COMPOUND_DICTIONARY, -18) SEPARATOR \
92
90
  BROTLI_ERROR_CODE(_ERROR_, DICTIONARY_NOT_SET, -19) SEPARATOR \
93
91
  BROTLI_ERROR_CODE(_ERROR_, INVALID_ARGUMENTS, -20) SEPARATOR \
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brotli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - miyucy