omnizip 0.3.7 → 0.3.9
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 +4 -4
- data/.rubocop_todo.yml +51 -50
- data/Gemfile +2 -0
- data/Rakefile +3 -0
- data/lib/omnizip/algorithms/lzma/bit_model.rb +1 -1
- data/lib/omnizip/algorithms/lzma/distance_coder.rb +5 -102
- data/lib/omnizip/algorithms/lzma/length_coder.rb +4 -92
- data/lib/omnizip/algorithms/lzma/literal_decoder.rb +4 -119
- data/lib/omnizip/algorithms/lzma/match_finder.rb +59 -29
- data/lib/omnizip/algorithms/lzma/optimal_encoder.rb +20 -12
- data/lib/omnizip/algorithms/lzma/range_decoder.rb +77 -269
- data/lib/omnizip/algorithms/lzma/range_encoder.rb +0 -9
- data/lib/omnizip/algorithms/lzma/xz_range_encoder_exact.rb +0 -15
- data/lib/omnizip/algorithms/lzma/xz_state.rb +0 -8
- data/lib/omnizip/algorithms/lzma/xz_utils_decoder.rb +183 -963
- data/lib/omnizip/filters/bcj2/decoder.rb +196 -130
- data/lib/omnizip/format_registry.rb +28 -3
- data/lib/omnizip/formats/msi/cab_extractor.rb +181 -0
- data/lib/omnizip/formats/msi/constants.rb +157 -0
- data/lib/omnizip/formats/msi/directory_resolver.rb +188 -0
- data/lib/omnizip/formats/msi/entry.rb +128 -0
- data/lib/omnizip/formats/msi/reader.rb +300 -0
- data/lib/omnizip/formats/msi/string_pool.rb +247 -0
- data/lib/omnizip/formats/msi/table_parser.rb +244 -0
- data/lib/omnizip/formats/msi.rb +87 -0
- data/lib/omnizip/formats/ole/allocation_table.rb +10 -0
- data/lib/omnizip/formats/ole/dirent.rb +12 -0
- data/lib/omnizip/formats/ole/ranges_io.rb +20 -2
- data/lib/omnizip/formats/ole/storage.rb +17 -1
- data/lib/omnizip/formats/ole.rb +0 -1
- data/lib/omnizip/formats/rar/decompressor.rb +37 -1
- data/lib/omnizip/formats/rar/rar5/writer.rb +1 -0
- data/lib/omnizip/formats/rar.rb +5 -1
- data/lib/omnizip/formats/rpm/header.rb +2 -2
- data/lib/omnizip/formats/seven_zip/bcj2_stream_decompressor.rb +99 -61
- data/lib/omnizip/formats/seven_zip/header_writer.rb +22 -60
- data/lib/omnizip/formats/seven_zip/parser.rb +13 -11
- data/lib/omnizip/formats/seven_zip/reader.rb +69 -17
- data/lib/omnizip/formats/seven_zip/split_archive_reader.rb +0 -14
- data/lib/omnizip/formats/seven_zip/writer.rb +18 -62
- data/lib/omnizip/formats/seven_zip.rb +64 -1
- data/lib/omnizip/formats/xar/toc.rb +2 -1
- data/lib/omnizip/formats.rb +3 -0
- data/lib/omnizip/implementations/xz_utils/lzma2/decoder.rb +15 -181
- data/lib/omnizip/implementations/xz_utils/lzma2/encoder.rb +3 -2
- data/lib/omnizip/version.rb +1 -1
- data/lib/omnizip.rb +43 -61
- data/lib/tasks/msi_test_files.rake +66 -0
- metadata +35 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: eb35ab3f87d9e1a1d4f96c65a86b9c5dcbd5df0f4da48443158dbe16d8e896e0
|
|
4
|
+
data.tar.gz: f9c8deab498097486bb07092f479b5097959cbc7f6b6ca171bc79996b08b6b91
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b518a237a3f41aac1d2e30d88cbc0e872320141d7f705d2bc33db3a2fbe22c5f784b8219c88001c54706571d07a3aa858f068c249e1da20efeb7c2afaca2f234
|
|
7
|
+
data.tar.gz: a18702ca45df7e9b6176b397c33d0e852a3a8a3880f58be16567aa13be7472c52b4774595a7fe1b90f3ef3929bab29d70e18ea22e4184add6a21b2c38c501909
|
data/.rubocop_todo.yml
CHANGED
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
# This configuration was generated by
|
|
2
2
|
# `rubocop --auto-gen-config`
|
|
3
|
-
# on 2026-
|
|
3
|
+
# on 2026-03-19 08:28:00 UTC using RuboCop version 1.85.1.
|
|
4
4
|
# The point is for the user to remove these configuration records
|
|
5
5
|
# one by one as the offenses are removed from the code base.
|
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
|
8
8
|
|
|
9
|
-
# Offense count:
|
|
9
|
+
# Offense count: 1
|
|
10
|
+
Gemspec/RequiredRubyVersion:
|
|
11
|
+
Exclude:
|
|
12
|
+
- 'omnizip.gemspec'
|
|
13
|
+
|
|
14
|
+
# Offense count: 5
|
|
10
15
|
# This cop supports safe autocorrection (--autocorrect).
|
|
11
16
|
# Configuration parameters: EnforcedStyle, IndentationWidth.
|
|
12
17
|
# SupportedStyles: with_first_argument, with_fixed_indentation
|
|
13
18
|
Layout/ArgumentAlignment:
|
|
14
|
-
Enabled: false
|
|
15
|
-
|
|
16
|
-
# Offense count: 1
|
|
17
|
-
# This cop supports safe autocorrection (--autocorrect).
|
|
18
|
-
# Configuration parameters: EnforcedStyle, IndentationWidth.
|
|
19
|
-
# SupportedStyles: with_first_element, with_fixed_indentation
|
|
20
|
-
Layout/ArrayAlignment:
|
|
21
19
|
Exclude:
|
|
22
|
-
- '
|
|
20
|
+
- 'spec/omnizip/formats/seven_zip/embedded_search_spec.rb'
|
|
23
21
|
|
|
24
22
|
# Offense count: 2
|
|
25
23
|
# This cop supports safe autocorrection (--autocorrect).
|
|
@@ -30,31 +28,19 @@ Layout/BlockAlignment:
|
|
|
30
28
|
- 'lib/omnizip/algorithms/lzma/lzip_decoder.rb'
|
|
31
29
|
- 'lib/omnizip/formats/xz_impl/block_decoder.rb'
|
|
32
30
|
|
|
33
|
-
# Offense count:
|
|
34
|
-
# This cop supports safe autocorrection (--autocorrect).
|
|
35
|
-
# Configuration parameters: EmptyLineBetweenMethodDefs, EmptyLineBetweenClassDefs, EmptyLineBetweenModuleDefs, DefLikeMacros, AllowAdjacentOneLineDefs, NumberOfEmptyLines.
|
|
36
|
-
Layout/EmptyLineBetweenDefs:
|
|
37
|
-
Exclude:
|
|
38
|
-
- 'lib/omnizip.rb'
|
|
39
|
-
- 'lib/omnizip/formats/rar.rb'
|
|
40
|
-
|
|
41
|
-
# Offense count: 17
|
|
31
|
+
# Offense count: 1485
|
|
42
32
|
# This cop supports safe autocorrection (--autocorrect).
|
|
43
|
-
|
|
44
|
-
Enabled: false
|
|
45
|
-
|
|
46
|
-
# Offense count: 1831
|
|
47
|
-
# This cop supports safe autocorrection (--autocorrect).
|
|
48
|
-
# Configuration parameters: Max, AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
|
|
33
|
+
# Configuration parameters: Max, AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, AllowRBSInlineAnnotation, AllowCopDirectives, AllowedPatterns, SplitStrings.
|
|
49
34
|
# URISchemes: http, https
|
|
50
35
|
Layout/LineLength:
|
|
51
36
|
Enabled: false
|
|
52
37
|
|
|
53
|
-
# Offense count:
|
|
38
|
+
# Offense count: 6
|
|
54
39
|
# This cop supports safe autocorrection (--autocorrect).
|
|
55
40
|
# Configuration parameters: AllowInHeredoc.
|
|
56
41
|
Layout/TrailingWhitespace:
|
|
57
|
-
|
|
42
|
+
Exclude:
|
|
43
|
+
- 'spec/omnizip/formats/seven_zip/embedded_search_spec.rb'
|
|
58
44
|
|
|
59
45
|
# Offense count: 13
|
|
60
46
|
# Configuration parameters: AllowedMethods.
|
|
@@ -71,15 +57,16 @@ Lint/ConstantDefinitionInBlock:
|
|
|
71
57
|
- 'spec/omnizip/seven_zip_tool_compatibility_spec.rb'
|
|
72
58
|
- 'spec/omnizip/xz_tool_compatibility_spec.rb'
|
|
73
59
|
|
|
74
|
-
# Offense count:
|
|
60
|
+
# Offense count: 36
|
|
75
61
|
# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches, IgnoreDuplicateElseBranch.
|
|
76
62
|
Lint/DuplicateBranch:
|
|
77
63
|
Enabled: false
|
|
78
64
|
|
|
79
|
-
# Offense count:
|
|
65
|
+
# Offense count: 9
|
|
80
66
|
Lint/DuplicateMethods:
|
|
81
67
|
Exclude:
|
|
82
68
|
- 'lib/omnizip/algorithms/lzma/xz_range_encoder_exact.rb'
|
|
69
|
+
- 'lib/omnizip/formats/msi/reader.rb'
|
|
83
70
|
- 'lib/omnizip/formats/xz.rb'
|
|
84
71
|
- 'lib/omnizip/implementations/xz_utils/lzma2/encoder.rb'
|
|
85
72
|
- 'lib/omnizip/models/filter_config.rb'
|
|
@@ -127,13 +114,6 @@ Lint/StructNewOverride:
|
|
|
127
114
|
- 'lib/omnizip/parallel/job_queue.rb'
|
|
128
115
|
- 'lib/omnizip/parity/par2_creator.rb'
|
|
129
116
|
|
|
130
|
-
# Offense count: 1
|
|
131
|
-
# Configuration parameters: AllowedPatterns.
|
|
132
|
-
# AllowedPatterns: (?-mix:(exactly|at_least|at_most)\(\d+\)\.times)
|
|
133
|
-
Lint/UnreachableLoop:
|
|
134
|
-
Exclude:
|
|
135
|
-
- 'lib/omnizip/algorithms/lzma/range_decoder.rb'
|
|
136
|
-
|
|
137
117
|
# Offense count: 2
|
|
138
118
|
# This cop supports safe autocorrection (--autocorrect).
|
|
139
119
|
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods, NotImplementedExceptions.
|
|
@@ -148,38 +128,38 @@ Lint/UselessConstantScoping:
|
|
|
148
128
|
Exclude:
|
|
149
129
|
- 'lib/omnizip/algorithms/lzma/optimal_encoder.rb'
|
|
150
130
|
|
|
151
|
-
# Offense count:
|
|
131
|
+
# Offense count: 553
|
|
152
132
|
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
|
|
153
133
|
Metrics/AbcSize:
|
|
154
134
|
Enabled: false
|
|
155
135
|
|
|
156
|
-
# Offense count:
|
|
136
|
+
# Offense count: 20
|
|
157
137
|
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
|
158
138
|
# AllowedMethods: refine
|
|
159
139
|
Metrics/BlockLength:
|
|
160
|
-
Max:
|
|
140
|
+
Max: 81
|
|
161
141
|
|
|
162
142
|
# Offense count: 5
|
|
163
143
|
# Configuration parameters: CountBlocks, CountModifierForms.
|
|
164
144
|
Metrics/BlockNesting:
|
|
165
145
|
Max: 6
|
|
166
146
|
|
|
167
|
-
# Offense count:
|
|
147
|
+
# Offense count: 263
|
|
168
148
|
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
|
|
169
149
|
Metrics/CyclomaticComplexity:
|
|
170
150
|
Enabled: false
|
|
171
151
|
|
|
172
|
-
# Offense count:
|
|
152
|
+
# Offense count: 961
|
|
173
153
|
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
|
174
154
|
Metrics/MethodLength:
|
|
175
|
-
Max:
|
|
155
|
+
Max: 238
|
|
176
156
|
|
|
177
157
|
# Offense count: 33
|
|
178
158
|
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
|
|
179
159
|
Metrics/ParameterLists:
|
|
180
160
|
Max: 20
|
|
181
161
|
|
|
182
|
-
# Offense count:
|
|
162
|
+
# Offense count: 182
|
|
183
163
|
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
|
|
184
164
|
Metrics/PerceivedComplexity:
|
|
185
165
|
Enabled: false
|
|
@@ -193,22 +173,19 @@ Naming/MethodParameterName:
|
|
|
193
173
|
# Offense count: 38
|
|
194
174
|
# Configuration parameters: Mode, AllowedMethods, AllowedPatterns, AllowBangMethods, WaywardPredicates.
|
|
195
175
|
# AllowedMethods: call
|
|
196
|
-
# WaywardPredicates: nonzero?
|
|
176
|
+
# WaywardPredicates: infinite?, nonzero?
|
|
197
177
|
Naming/PredicateMethod:
|
|
198
178
|
Enabled: false
|
|
199
179
|
|
|
200
|
-
# Offense count:
|
|
180
|
+
# Offense count: 37
|
|
201
181
|
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
|
|
202
182
|
# SupportedStyles: snake_case, normalcase, non_integer
|
|
203
183
|
# AllowedIdentifiers: TLS1_1, TLS1_2, capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
|
|
204
184
|
Naming/VariableNumber:
|
|
205
185
|
Exclude:
|
|
206
186
|
- 'lib/omnizip/algorithms/lzma/bit_model.rb'
|
|
207
|
-
- 'lib/omnizip/algorithms/lzma/distance_coder.rb'
|
|
208
|
-
- 'lib/omnizip/algorithms/lzma/literal_decoder.rb'
|
|
209
187
|
- 'lib/omnizip/algorithms/lzma/range_encoder.rb'
|
|
210
188
|
- 'lib/omnizip/algorithms/lzma/xz_buffered_range_encoder.rb'
|
|
211
|
-
- 'lib/omnizip/algorithms/lzma/xz_utils_decoder.rb'
|
|
212
189
|
- 'lib/omnizip/formats/rar/rar5/compression/lzss.rb'
|
|
213
190
|
- 'lib/omnizip/formats/xz_impl/block_decoder.rb'
|
|
214
191
|
- 'lib/omnizip/implementations/seven_zip/lzma/range_encoder.rb'
|
|
@@ -218,13 +195,14 @@ Naming/VariableNumber:
|
|
|
218
195
|
- 'spec/omnizip/parity/reed_solomon_encoder_spec.rb'
|
|
219
196
|
- 'spec/omnizip/parity/reed_solomon_matrix_spec.rb'
|
|
220
197
|
|
|
221
|
-
# Offense count:
|
|
198
|
+
# Offense count: 9
|
|
222
199
|
# Configuration parameters: MinSize.
|
|
223
200
|
Performance/CollectionLiteralInLoop:
|
|
224
201
|
Exclude:
|
|
225
202
|
- 'lib/omnizip/commands/archive_create_command.rb'
|
|
226
203
|
- 'lib/omnizip/formats/iso/directory_builder.rb'
|
|
227
204
|
- 'lib/omnizip/formats/iso/writer.rb'
|
|
205
|
+
- 'lib/omnizip/formats/msi/constants.rb'
|
|
228
206
|
- 'lib/omnizip/formats/seven_zip/header_writer.rb'
|
|
229
207
|
- 'lib/omnizip/parity/models/file_description_packet.rb'
|
|
230
208
|
- 'lib/omnizip/parity/par2_repairer.rb'
|
|
@@ -235,12 +213,14 @@ Performance/MapMethodChain:
|
|
|
235
213
|
Exclude:
|
|
236
214
|
- 'lib/omnizip/commands/archive_create_command.rb'
|
|
237
215
|
|
|
238
|
-
# Offense count:
|
|
216
|
+
# Offense count: 11
|
|
239
217
|
Security/Open:
|
|
240
218
|
Exclude:
|
|
241
219
|
- 'lib/omnizip/formats/cpio.rb'
|
|
242
220
|
- 'lib/omnizip/formats/iso.rb'
|
|
221
|
+
- 'lib/omnizip/formats/msi.rb'
|
|
243
222
|
- 'lib/omnizip/zip/file.rb'
|
|
223
|
+
- 'lib/tasks/msi_test_files.rake'
|
|
244
224
|
|
|
245
225
|
# Offense count: 6
|
|
246
226
|
# This cop supports safe autocorrection (--autocorrect).
|
|
@@ -260,6 +240,20 @@ Style/EmptyElse:
|
|
|
260
240
|
- 'lib/omnizip/algorithms/ppmd7/encoder.rb'
|
|
261
241
|
- 'lib/omnizip/formats/iso/volume_descriptor.rb'
|
|
262
242
|
|
|
243
|
+
# Offense count: 11
|
|
244
|
+
Style/FileOpen:
|
|
245
|
+
Exclude:
|
|
246
|
+
- 'lib/omnizip/chunked/writer.rb'
|
|
247
|
+
- 'lib/omnizip/formats/iso/reader.rb'
|
|
248
|
+
- 'lib/omnizip/formats/rar/rar5/multi_volume/volume_writer.rb'
|
|
249
|
+
- 'lib/omnizip/formats/rpm.rb'
|
|
250
|
+
- 'lib/omnizip/formats/seven_zip/split_archive_writer.rb'
|
|
251
|
+
- 'lib/omnizip/formats/tar/writer.rb'
|
|
252
|
+
- 'lib/omnizip/formats/xar/reader.rb'
|
|
253
|
+
- 'lib/omnizip/zip/input_stream.rb'
|
|
254
|
+
- 'lib/omnizip/zip/output_stream.rb'
|
|
255
|
+
- 'spec/omnizip/formats/rpm_spec.rb'
|
|
256
|
+
|
|
263
257
|
# Offense count: 161
|
|
264
258
|
# This cop supports safe autocorrection (--autocorrect).
|
|
265
259
|
# Configuration parameters: MaxUnannotatedPlaceholdersAllowed, Mode, AllowedMethods, AllowedPatterns.
|
|
@@ -273,6 +267,13 @@ Style/MixinUsage:
|
|
|
273
267
|
- 'spec/scripts/debug_7z_structure.rb'
|
|
274
268
|
- 'spec/scripts/debug_writer_output.rb'
|
|
275
269
|
|
|
270
|
+
# Offense count: 3
|
|
271
|
+
# Configuration parameters: AllowedClasses.
|
|
272
|
+
Style/OneClassPerFile:
|
|
273
|
+
Exclude:
|
|
274
|
+
- 'lib/omnizip.rb'
|
|
275
|
+
- 'lib/omnizip/algorithms/lzma2.rb'
|
|
276
|
+
|
|
276
277
|
# Offense count: 3
|
|
277
278
|
# Configuration parameters: AllowedMethods.
|
|
278
279
|
# AllowedMethods: respond_to_missing?
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
|
@@ -49,6 +49,8 @@ module Omnizip
|
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
# Position encoders for slots 4-13
|
|
52
|
+
# SDK convention: size = NUM_FULL_DISTANCES - END_POS_MODEL_INDEX = 128 - 14 = 114
|
|
53
|
+
# Indexed by: base - slot - 1 (matches LZMA SDK and XZ Utils)
|
|
52
54
|
@pos_encoders = Array.new(NUM_FULL_DISTANCES - END_POS_MODEL_INDEX) do
|
|
53
55
|
BitModel.new
|
|
54
56
|
end
|
|
@@ -71,19 +73,11 @@ module Omnizip
|
|
|
71
73
|
#
|
|
72
74
|
# @return [void]
|
|
73
75
|
def reset_models
|
|
74
|
-
if ENV.fetch("DEBUG_RESET_MODELS",
|
|
75
|
-
nil) && ENV.fetch("LZMA_DEBUG_DISTANCE", nil)
|
|
76
|
-
puts " [DistanceCoder.reset_models] Resetting #{@slot_encoders.size} len_states, each with #{@slot_encoders[0]&.size || '?'} models"
|
|
77
|
-
end
|
|
78
76
|
@slot_encoders.each do |len_state_models|
|
|
79
77
|
len_state_models.each(&:reset)
|
|
80
78
|
end
|
|
81
79
|
@pos_encoders.each(&:reset)
|
|
82
80
|
@align_encoder.each(&:reset)
|
|
83
|
-
if ENV.fetch("DEBUG_RESET_MODELS",
|
|
84
|
-
nil) && ENV.fetch("LZMA_DEBUG_DISTANCE", nil)
|
|
85
|
-
puts " [DistanceCoder.reset_models] Done resetting"
|
|
86
|
-
end
|
|
87
81
|
end
|
|
88
82
|
|
|
89
83
|
# Encode a match distance using SDK-compatible encoding
|
|
@@ -95,11 +89,6 @@ module Omnizip
|
|
|
95
89
|
def encode(range_encoder, distance, len_state)
|
|
96
90
|
slot = get_dist_slot(distance)
|
|
97
91
|
|
|
98
|
-
if ENV["LZMA_DEBUG_ENCODE"]
|
|
99
|
-
puts "[DistanceCoder.encode] distance=#{distance} slot=#{slot} len_state=#{len_state}"
|
|
100
|
-
puts "[DistanceCoder.encode] CALLING encode_tree with symbol=#{slot}"
|
|
101
|
-
end
|
|
102
|
-
|
|
103
92
|
# Encode the slot using the appropriate slot encoder
|
|
104
93
|
encode_tree(range_encoder, @slot_encoders[len_state], slot,
|
|
105
94
|
NUM_DIST_SLOT_BITS)
|
|
@@ -111,6 +100,7 @@ module Omnizip
|
|
|
111
100
|
|
|
112
101
|
if slot < END_POS_MODEL_INDEX
|
|
113
102
|
# Slots 4-13: Use position encoders (reverse tree encoding)
|
|
103
|
+
# SDK/XZ Utils convention: base_idx = base - slot - 1
|
|
114
104
|
encode_reverse_tree(range_encoder,
|
|
115
105
|
@pos_encoders,
|
|
116
106
|
base - slot - 1,
|
|
@@ -138,61 +128,24 @@ module Omnizip
|
|
|
138
128
|
# @param len_state [Integer] Length state for slot selection
|
|
139
129
|
# @return [Integer] Decoded distance value (before adding 1)
|
|
140
130
|
def decode(range_decoder, len_state)
|
|
141
|
-
# DEBUG: Trace specific calls to find corruption
|
|
142
|
-
$distance_decode_count ||= 0
|
|
143
|
-
debug_calls = (320..330)
|
|
144
|
-
debug_this = debug_calls.include?($distance_decode_count)
|
|
145
|
-
trace_326 = ($distance_decode_count == 326)
|
|
146
|
-
trace_325 = ($distance_decode_count == 325)
|
|
147
|
-
|
|
148
|
-
# DEBUG: Trace large distances (> 100000)
|
|
149
|
-
trace_large = $distance_decode_count.between?(25,
|
|
150
|
-
35) || $distance_decode_count.between?(
|
|
151
|
-
315, 330
|
|
152
|
-
)
|
|
153
|
-
|
|
154
|
-
# DEBUG: Trace all when LZMA_DEBUG_DISTANCE is set
|
|
155
|
-
trace_all = ENV.fetch("LZMA_DEBUG_DISTANCE", nil)
|
|
156
|
-
|
|
157
|
-
if (trace_325 || trace_large || trace_all) && ENV.fetch(
|
|
158
|
-
"LZMA_DEBUG_DISTANCE", nil
|
|
159
|
-
)
|
|
160
|
-
puts " [DistanceCoder.decode ##{$distance_decode_count}] START - len_state=#{len_state}"
|
|
161
|
-
puts " BEFORE: range=#{range_decoder.range.inspect}, code=#{range_decoder.code.inspect}"
|
|
162
|
-
end
|
|
163
|
-
|
|
164
131
|
slot = decode_tree(range_decoder, @slot_encoders[len_state],
|
|
165
132
|
NUM_DIST_SLOT_BITS)
|
|
166
133
|
|
|
167
|
-
if (debug_this || trace_large || trace_all) && ENV.fetch(
|
|
168
|
-
"LZMA_DEBUG_DISTANCE", nil
|
|
169
|
-
)
|
|
170
|
-
puts " [DistanceCoder.decode ##{$distance_decode_count}] len_state=#{len_state}, slot=#{slot}"
|
|
171
|
-
puts " @slot_encoders[#{len_state}] object_id=#{@slot_encoders[len_state].object_id}"
|
|
172
|
-
end
|
|
173
|
-
|
|
174
134
|
# Decode extra bits based on slot
|
|
175
135
|
if slot < START_POS_MODEL_INDEX
|
|
176
136
|
# Slots 0-3: No extra bits
|
|
177
|
-
$distance_decode_count += 1
|
|
178
|
-
if debug_this && ENV.fetch("LZMA_DEBUG_DISTANCE", nil)
|
|
179
|
-
puts " -> distance=#{slot}"
|
|
180
|
-
end
|
|
181
137
|
slot
|
|
182
138
|
else
|
|
183
139
|
footer_bits = (slot >> 1) - 1
|
|
184
140
|
|
|
185
141
|
if slot < END_POS_MODEL_INDEX
|
|
186
142
|
# Slots 4-13: Use position encoders (reverse tree decoding)
|
|
143
|
+
# SDK/XZ Utils convention: base_idx = base - slot - 1
|
|
187
144
|
base = (2 | (slot & 1)) << footer_bits
|
|
188
145
|
result = base + decode_reverse_tree(range_decoder,
|
|
189
146
|
@pos_encoders,
|
|
190
147
|
base - slot - 1,
|
|
191
148
|
footer_bits)
|
|
192
|
-
$distance_decode_count += 1
|
|
193
|
-
if debug_this && ENV.fetch("LZMA_DEBUG_DISTANCE", nil)
|
|
194
|
-
puts " -> distance=#{result} (slot #{slot})"
|
|
195
|
-
end
|
|
196
149
|
else
|
|
197
150
|
# Slots 14+: Fixed direct bits + aligned bits
|
|
198
151
|
# XZ Utils pattern (lzma_decoder.c:500-514):
|
|
@@ -225,23 +178,10 @@ module Omnizip
|
|
|
225
178
|
@align_encoder,
|
|
226
179
|
0,
|
|
227
180
|
DIST_ALIGN_BITS)
|
|
228
|
-
if trace_326 && ENV.fetch("LZMA_DEBUG_DISTANCE", nil)
|
|
229
|
-
puts " TRACE_326: low_bits=#{low_bits}"
|
|
230
|
-
end
|
|
231
181
|
|
|
232
182
|
# Final result: (result << 4) + low_bits
|
|
233
183
|
# NOTE: slot value is NOT added (XZ Utils pattern - line 513 adds symbol for EOPM check only)
|
|
234
184
|
result = (result << DIST_ALIGN_BITS) + low_bits
|
|
235
|
-
$distance_decode_count += 1
|
|
236
|
-
if (debug_this || trace_large) && ENV.fetch(
|
|
237
|
-
"LZMA_DEBUG_DISTANCE", nil
|
|
238
|
-
)
|
|
239
|
-
puts " -> slot=#{slot}, result_after_direct=#{result >> DIST_ALIGN_BITS}, low_bits=#{low_bits}, distance=#{result}"
|
|
240
|
-
end
|
|
241
|
-
if result > 100000
|
|
242
|
-
puts " [LARGE_DISTANCE ##{$distance_decode_count}] distance=#{result}, slot=#{slot}" if ENV["LZMA_DEBUG_DISTANCE"]
|
|
243
|
-
puts " BEFORE: range_decoder.range=#{range_decoder.range}, range_decoder.code=#{range_decoder.code}" if ENV["LZMA_DEBUG_DISTANCE"]
|
|
244
|
-
end
|
|
245
185
|
end
|
|
246
186
|
result
|
|
247
187
|
end
|
|
@@ -321,29 +261,11 @@ module Omnizip
|
|
|
321
261
|
# @return [void]
|
|
322
262
|
def encode_tree(range_encoder, models, symbol, num_bits)
|
|
323
263
|
m = 1
|
|
324
|
-
trace_all = ENV.fetch("TRACE_ALL_SLOT_ENCODE", nil)
|
|
325
|
-
iteration = 0
|
|
326
|
-
|
|
327
|
-
if trace_all && ENV.fetch("LZMA_DEBUG_ENCODE", nil)
|
|
328
|
-
puts " [encode_tree START] RECEIVED symbol=#{symbol}, num_bits=#{num_bits}"
|
|
329
|
-
puts " BEFORE: range=#{range_encoder.range}, low=#{range_encoder.low}"
|
|
330
|
-
end
|
|
331
|
-
|
|
332
264
|
(num_bits - 1).downto(0) do |i|
|
|
333
|
-
iteration += 1
|
|
334
265
|
bit = (symbol >> i) & 1
|
|
335
|
-
if trace_all && ENV.fetch("LZMA_DEBUG_ENCODE", nil)
|
|
336
|
-
model_idx = m
|
|
337
|
-
puts " [#{iteration}/#{num_bits}] i=#{i}, bit=#{bit}, m=#{m}, model_idx=#{model_idx}, prob=#{models[m].probability}"
|
|
338
|
-
end
|
|
339
266
|
range_encoder.encode_bit(models[m], bit)
|
|
340
267
|
m = (m << 1) | bit
|
|
341
268
|
end
|
|
342
|
-
|
|
343
|
-
if trace_all && ENV.fetch("LZMA_DEBUG_ENCODE", nil)
|
|
344
|
-
puts " AFTER: range=#{range_encoder.range}, low=#{range_encoder.low}"
|
|
345
|
-
puts " [encode_tree END] ENCODED symbol=#{symbol}"
|
|
346
|
-
end
|
|
347
269
|
end
|
|
348
270
|
|
|
349
271
|
# Decode a value using a tree of bit models
|
|
@@ -355,29 +277,10 @@ module Omnizip
|
|
|
355
277
|
def decode_tree(range_decoder, models, num_bits)
|
|
356
278
|
m = 1
|
|
357
279
|
symbol = 0
|
|
358
|
-
trace_this = (num_bits == 6 && ENV.fetch("TRACE_SLOT_DECODE",
|
|
359
|
-
nil)) || ($distance_decode_count == 28)
|
|
360
|
-
trace_all = ENV.fetch("TRACE_ALL_SLOT_DECODE", nil)
|
|
361
|
-
iteration = 0
|
|
362
|
-
|
|
363
|
-
if (trace_this || trace_all) && ENV.fetch("LZMA_DEBUG_DISTANCE", nil)
|
|
364
|
-
puts " [decode_tree START] num_bits=#{num_bits}, range=#{range_decoder.range}, code=#{range_decoder.code}"
|
|
365
|
-
puts " models array object_id=#{models.object_id}"
|
|
366
|
-
end
|
|
367
|
-
|
|
368
280
|
(num_bits - 1).downto(0) do |i|
|
|
369
|
-
|
|
370
|
-
model = models[m]
|
|
371
|
-
bit = range_decoder.decode_bit(model)
|
|
281
|
+
bit = range_decoder.decode_bit(models[m])
|
|
372
282
|
m = (m << 1) | bit
|
|
373
283
|
symbol |= (bit << i)
|
|
374
|
-
if (trace_this || trace_all) && ENV.fetch("LZMA_DEBUG_DISTANCE",
|
|
375
|
-
nil)
|
|
376
|
-
puts " [#{iteration}/#{num_bits}] i=#{i}, bit=#{bit}, m=#{m}, model.object_id=#{model.object_id}, prob=#{model.probability}, symbol=#{symbol}"
|
|
377
|
-
end
|
|
378
|
-
end
|
|
379
|
-
if (trace_this || trace_all) && ENV.fetch("LZMA_DEBUG_DISTANCE", nil)
|
|
380
|
-
puts " [decode_tree END] symbol=#{symbol}"
|
|
381
284
|
end
|
|
382
285
|
symbol
|
|
383
286
|
end
|
|
@@ -67,67 +67,25 @@ module Omnizip
|
|
|
67
67
|
# @param pos_state [Integer] Position state for tree selection
|
|
68
68
|
# @return [void]
|
|
69
69
|
def encode(range_encoder, length, pos_state)
|
|
70
|
-
trace_encode = ENV.fetch("LZMA_DEBUG_ENCODE",
|
|
71
|
-
nil) && ENV.fetch("TRACE_LENGTH_CODER", nil)
|
|
72
|
-
|
|
73
|
-
if trace_encode
|
|
74
|
-
puts " [LengthCoder.encode] START: length=#{length}, pos_state=#{pos_state}"
|
|
75
|
-
puts " @choice.prob=#{@choice.probability} @choice2.prob=#{@choice2.probability}"
|
|
76
|
-
end
|
|
77
|
-
|
|
78
70
|
if length < LEN_LOW_SYMBOLS
|
|
79
71
|
# 0-7: Use low tree
|
|
80
|
-
if trace_encode
|
|
81
|
-
puts " Using LOW tree (length #{length} < #{LEN_LOW_SYMBOLS})"
|
|
82
|
-
puts " Encoding choice=0 with prob=#{@choice.probability}"
|
|
83
|
-
end
|
|
84
72
|
range_encoder.encode_bit(@choice, 0)
|
|
85
|
-
if trace_encode
|
|
86
|
-
puts " After choice: @choice.prob=#{@choice.probability}"
|
|
87
|
-
end
|
|
88
73
|
encode_tree(range_encoder, @low[pos_state], length,
|
|
89
74
|
NUM_LEN_LOW_BITS)
|
|
90
75
|
elsif length < LEN_LOW_SYMBOLS + LEN_MID_SYMBOLS
|
|
91
76
|
# 8-15: Use mid tree
|
|
92
|
-
if trace_encode
|
|
93
|
-
puts " Using MID tree (length #{length} < #{LEN_LOW_SYMBOLS + LEN_MID_SYMBOLS})"
|
|
94
|
-
puts " Encoding choice=1 with prob=#{@choice.probability}"
|
|
95
|
-
end
|
|
96
77
|
range_encoder.encode_bit(@choice, 1)
|
|
97
|
-
if trace_encode
|
|
98
|
-
puts " After choice: @choice.prob=#{@choice.probability}"
|
|
99
|
-
puts " Encoding choice2=0 with prob=#{@choice2.probability}"
|
|
100
|
-
end
|
|
101
78
|
range_encoder.encode_bit(@choice2, 0)
|
|
102
|
-
if trace_encode
|
|
103
|
-
puts " After choice2: @choice2.prob=#{@choice2.probability}"
|
|
104
|
-
end
|
|
105
79
|
encode_tree(range_encoder, @mid[pos_state],
|
|
106
80
|
length - LEN_LOW_SYMBOLS, NUM_LEN_MID_BITS)
|
|
107
81
|
else
|
|
108
82
|
# 16+: Use high tree
|
|
109
|
-
if trace_encode
|
|
110
|
-
puts " Using HIGH tree (length #{length} >= #{LEN_LOW_SYMBOLS + LEN_MID_SYMBOLS})"
|
|
111
|
-
puts " Encoding choice=1 with prob=#{@choice.probability}"
|
|
112
|
-
end
|
|
113
83
|
range_encoder.encode_bit(@choice, 1)
|
|
114
|
-
if trace_encode
|
|
115
|
-
puts " After choice: @choice.prob=#{@choice.probability}"
|
|
116
|
-
puts " Encoding choice2=1 with prob=#{@choice2.probability}"
|
|
117
|
-
end
|
|
118
84
|
range_encoder.encode_bit(@choice2, 1)
|
|
119
|
-
if trace_encode
|
|
120
|
-
puts " After choice2: @choice2.prob=#{@choice2.probability}"
|
|
121
|
-
end
|
|
122
85
|
encode_tree(range_encoder, @high,
|
|
123
86
|
length - LEN_LOW_SYMBOLS - LEN_MID_SYMBOLS,
|
|
124
87
|
NUM_LEN_HIGH_BITS)
|
|
125
88
|
end
|
|
126
|
-
|
|
127
|
-
if trace_encode
|
|
128
|
-
puts " FINAL @choice.prob=#{@choice.probability} @choice2.prob=#{@choice2.probability}"
|
|
129
|
-
puts " [LengthCoder.encode] END"
|
|
130
|
-
end
|
|
131
89
|
end
|
|
132
90
|
|
|
133
91
|
# Decode a match length using SDK-compatible decoding
|
|
@@ -136,58 +94,21 @@ module Omnizip
|
|
|
136
94
|
# @param pos_state [Integer] Position state for tree selection
|
|
137
95
|
# @return [Integer] Decoded length value (before adding MATCH_LEN_MIN)
|
|
138
96
|
def decode(range_decoder, pos_state)
|
|
139
|
-
trace_decode = ENV.fetch("LZMA_DEBUG_DISTANCE",
|
|
140
|
-
nil) && ENV.fetch("TRACE_LENGTH_CODER", nil)
|
|
141
|
-
|
|
142
|
-
if trace_decode
|
|
143
|
-
caller_loc = caller_locations(2, 1).first
|
|
144
|
-
puts " [LengthCoder.decode] START: pos_state=#{pos_state}"
|
|
145
|
-
puts " self.object_id=#{object_id}"
|
|
146
|
-
puts " @choice.object_id=#{@choice.object_id} prob=#{@choice.probability}"
|
|
147
|
-
puts " @choice2.object_id=#{@choice2.object_id} prob=#{@choice2.probability}"
|
|
148
|
-
puts " Called from: #{caller_loc.label} at #{caller_loc.lineno}"
|
|
149
|
-
end
|
|
150
|
-
|
|
151
97
|
choice_bit = range_decoder.decode_bit(@choice)
|
|
152
|
-
if trace_decode
|
|
153
|
-
puts " Decoded choice=#{choice_bit} with prob=#{@choice.probability}"
|
|
154
|
-
puts " After choice decode: @choice.prob=#{@choice.probability}"
|
|
155
|
-
end
|
|
156
98
|
|
|
157
99
|
if choice_bit.zero?
|
|
158
100
|
# Low tree
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
end
|
|
162
|
-
result = decode_tree(range_decoder, @low[pos_state],
|
|
163
|
-
NUM_LEN_LOW_BITS)
|
|
101
|
+
decode_tree(range_decoder, @low[pos_state],
|
|
102
|
+
NUM_LEN_LOW_BITS)
|
|
164
103
|
elsif range_decoder.decode_bit(@choice2).zero?
|
|
165
104
|
# Mid tree
|
|
166
|
-
|
|
167
|
-
puts " Decoded choice2=0 with prob=#{@choice2.probability}"
|
|
168
|
-
puts " After choice2 decode: @choice2.prob=#{@choice2.probability}"
|
|
169
|
-
puts " Using MID tree"
|
|
170
|
-
end
|
|
171
|
-
result = LEN_LOW_SYMBOLS +
|
|
105
|
+
LEN_LOW_SYMBOLS +
|
|
172
106
|
decode_tree(range_decoder, @mid[pos_state], NUM_LEN_MID_BITS)
|
|
173
107
|
else
|
|
174
108
|
# High tree
|
|
175
|
-
|
|
176
|
-
puts " Decoded choice2=1 with prob=#{@choice2.probability}"
|
|
177
|
-
puts " After choice2 decode: @choice2.prob=#{@choice2.probability}"
|
|
178
|
-
puts " Using HIGH tree"
|
|
179
|
-
end
|
|
180
|
-
result = LEN_LOW_SYMBOLS + LEN_MID_SYMBOLS +
|
|
109
|
+
LEN_LOW_SYMBOLS + LEN_MID_SYMBOLS +
|
|
181
110
|
decode_tree(range_decoder, @high, NUM_LEN_HIGH_BITS)
|
|
182
111
|
end
|
|
183
|
-
|
|
184
|
-
if trace_decode
|
|
185
|
-
puts " FINAL @choice.prob=#{@choice.probability} @choice2.prob=#{@choice2.probability}"
|
|
186
|
-
puts " Result: length_encoded=#{result}"
|
|
187
|
-
puts " [LengthCoder.decode] END"
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
result
|
|
191
112
|
end
|
|
192
113
|
|
|
193
114
|
# Reset probability models to initial values
|
|
@@ -197,12 +118,6 @@ module Omnizip
|
|
|
197
118
|
#
|
|
198
119
|
# @return [void]
|
|
199
120
|
def reset_models
|
|
200
|
-
if ENV["TRACE_RESET_MODELS"]
|
|
201
|
-
puts " [LengthCoder.reset_models] CALLED!"
|
|
202
|
-
puts " Before reset: @choice.prob=#{@choice.probability} @choice2.prob=#{@choice2.probability}"
|
|
203
|
-
caller_loc = caller_locations(2, 1).first
|
|
204
|
-
puts " Called from: #{caller_loc.label} at #{caller_loc.path}:#{caller_loc.lineno}"
|
|
205
|
-
end
|
|
206
121
|
@choice.reset
|
|
207
122
|
@choice2.reset
|
|
208
123
|
|
|
@@ -215,9 +130,6 @@ module Omnizip
|
|
|
215
130
|
end
|
|
216
131
|
|
|
217
132
|
@high.each(&:reset)
|
|
218
|
-
if ENV["TRACE_RESET_MODELS"]
|
|
219
|
-
puts " After reset: @choice.prob=#{@choice.probability} @choice2.prob=#{@choice2.probability}"
|
|
220
|
-
end
|
|
221
133
|
end
|
|
222
134
|
|
|
223
135
|
private
|