node-liblzma 2.0.0 → 2.1.0
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.
- package/README.md +156 -63
- package/binding.gyp +7 -2
- package/index.d.ts +26 -3
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +26 -15
- package/lib/errors.js.map +1 -1
- package/lib/lzma.d.ts +236 -2
- package/lib/lzma.d.ts.map +1 -1
- package/lib/lzma.js +225 -39
- package/lib/lzma.js.map +1 -1
- package/lib/pool.d.ts.map +1 -1
- package/lib/pool.js +9 -3
- package/lib/pool.js.map +1 -1
- package/lib/types.d.ts +68 -1
- package/lib/types.d.ts.map +1 -1
- package/package.json +34 -17
- package/scripts/build_xz_with_cmake.py +23 -26
- package/scripts/download_xz_from_github.py +14 -13
- package/src/bindings/node-liblzma.cpp +40 -4
- package/src/bindings/node-liblzma.hpp +2 -1
- package/xz-version.json +3 -3
- package/.claude/settings.local.json +0 -92
- package/.gitattributes +0 -3
- package/.release-it.json +0 -6
- package/CHANGELOG.md +0 -209
- package/History.md +0 -79
- package/RELEASING.md +0 -131
- package/biome.json +0 -81
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -87
- package/coverage/errors.ts.html +0 -586
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +0 -146
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/errors.ts.html +0 -586
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -146
- package/coverage/lcov-report/lzma.ts.html +0 -2596
- package/coverage/lcov-report/pool.ts.html +0 -769
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov.info +0 -636
- package/coverage/lzma.ts.html +0 -2596
- package/coverage/pool.ts.html +0 -769
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -210
- package/coverage-reports/assets/monocart-coverage-app.js +0 -2
- package/coverage-reports/coverage-data.js +0 -1
- package/coverage-reports/index.html +0 -48
- package/err.log +0 -26
- package/pnpm-workspace.yaml +0 -3
- package/scripts/analyze-coverage.js +0 -132
- package/scripts/compare-coverage-tools.js +0 -93
- package/scripts/prebuildify.py +0 -13
- package/src/errors.ts +0 -167
- package/src/lzma.ts +0 -839
- package/src/pool.ts +0 -228
- package/src/types.ts +0 -30
- package/tsconfig.json +0 -50
- package/vitest.config.istanbul.ts +0 -29
- package/vitest.config.monocart.ts +0 -44
- package/vitest.config.ts +0 -44
package/lib/types.d.ts
CHANGED
|
@@ -17,11 +17,78 @@ export interface LZMAOptions {
|
|
|
17
17
|
/** Flush flag to use */
|
|
18
18
|
flushFlag?: number;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Callback function for asynchronous compression/decompression operations.
|
|
22
|
+
* @param error - Error object if operation failed, null otherwise
|
|
23
|
+
* @param result - Compressed or decompressed data buffer
|
|
24
|
+
*/
|
|
20
25
|
export type CompressionCallback = (error: Error | null, result?: Buffer) => void;
|
|
26
|
+
/**
|
|
27
|
+
* LZMA action type for stream operations.
|
|
28
|
+
* - `0` (RUN): Normal processing
|
|
29
|
+
* - `1` (SYNC_FLUSH): Flush pending output
|
|
30
|
+
* - `2` (FULL_FLUSH): Flush and reset encoder state
|
|
31
|
+
* - `3` (FINISH): Finish the stream
|
|
32
|
+
*/
|
|
21
33
|
export type LZMAActionType = 0 | 1 | 2 | 3;
|
|
34
|
+
/**
|
|
35
|
+
* LZMA status codes returned by operations.
|
|
36
|
+
* - `0` (OK): Operation completed successfully
|
|
37
|
+
* - `1` (STREAM_END): End of stream reached
|
|
38
|
+
* - `2` (NO_CHECK): Input has no integrity check
|
|
39
|
+
* - `3` (UNSUPPORTED_CHECK): Cannot calculate integrity check
|
|
40
|
+
* - `4` (GET_CHECK): Integrity check available
|
|
41
|
+
* - `5` (MEM_ERROR): Memory allocation failed
|
|
42
|
+
* - `6` (MEMLIMIT_ERROR): Memory limit reached
|
|
43
|
+
* - `7` (FORMAT_ERROR): File format not recognized
|
|
44
|
+
* - `8` (OPTIONS_ERROR): Invalid options
|
|
45
|
+
* - `9` (DATA_ERROR): Data is corrupt
|
|
46
|
+
* - `10` (BUF_ERROR): No progress possible
|
|
47
|
+
* - `11` (PROG_ERROR): Programming error
|
|
48
|
+
*/
|
|
22
49
|
export type LZMAStatusType = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11;
|
|
50
|
+
/**
|
|
51
|
+
* Integrity check type for XZ streams.
|
|
52
|
+
* - `0` (NONE): No integrity check
|
|
53
|
+
* - `1` (CRC32): 32-bit CRC
|
|
54
|
+
* - `4` (CRC64): 64-bit CRC (recommended)
|
|
55
|
+
* - `10` (SHA256): SHA-256 hash
|
|
56
|
+
*/
|
|
23
57
|
export type CheckType = 0 | 1 | 4 | 10;
|
|
24
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Compression preset level (0-9), optionally combined with EXTREME flag.
|
|
60
|
+
* Higher values = better compression but slower.
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* const preset = 6; // Default compression
|
|
64
|
+
* const extreme = 6 | 0x80000000; // Default with extreme flag
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export type PresetType = number;
|
|
68
|
+
/**
|
|
69
|
+
* Filter type for LZMA2 compression chain.
|
|
70
|
+
* - `0x21` (LZMA2): Main compression filter
|
|
71
|
+
* - `0x03` (X86): BCJ filter for x86 executables
|
|
72
|
+
* - `0x04` (POWERPC): BCJ filter for PowerPC
|
|
73
|
+
* - `0x06` (IA64): BCJ filter for IA-64
|
|
74
|
+
* - `0x07` (ARM): BCJ filter for ARM
|
|
75
|
+
* - `0x08` (ARMTHUMB): BCJ filter for ARM-Thumb
|
|
76
|
+
* - `0x09` (SPARC): BCJ filter for SPARC
|
|
77
|
+
*/
|
|
25
78
|
export type FilterType = 0x21 | 0x03 | 0x04 | 0x06 | 0x07 | 0x08 | 0x09;
|
|
79
|
+
/**
|
|
80
|
+
* Compression mode.
|
|
81
|
+
* - `1` (FAST): Faster compression, less memory
|
|
82
|
+
* - `2` (NORMAL): Better compression ratio
|
|
83
|
+
*/
|
|
26
84
|
export type ModeType = 1 | 2;
|
|
85
|
+
/**
|
|
86
|
+
* Progress event data emitted during compression/decompression
|
|
87
|
+
*/
|
|
88
|
+
export interface ProgressInfo {
|
|
89
|
+
/** Total bytes read from input so far */
|
|
90
|
+
bytesRead: number;
|
|
91
|
+
/** Total bytes written to output so far */
|
|
92
|
+
bytesWritten: number;
|
|
93
|
+
}
|
|
27
94
|
//# sourceMappingURL=types.d.ts.map
|
package/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,WAAW;IAC1B,2BAA2B;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+BAA+B;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8BAA8B;IAC9B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,uBAAuB;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gCAAgC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wBAAwB;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,WAAW;IAC1B,2BAA2B;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+BAA+B;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8BAA8B;IAC9B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,uBAAuB;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gCAAgC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wBAAwB;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;AAEjF;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAE3C;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC;AAE7E;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;AAEvC;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC;;;;;;;;;GASG;AACH,MAAM,MAAM,UAAU,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAExE;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,CAAC,CAAC;AAE7B;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,yCAAyC;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,2CAA2C;IAC3C,YAAY,EAAE,MAAM,CAAC;CACtB"}
|
package/package.json
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-liblzma",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "NodeJS wrapper for liblzma",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/lzma.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
9
|
"import": "./lib/lzma.js",
|
|
10
|
-
"types": "./index.d.ts"
|
|
10
|
+
"types": "./index.d.ts",
|
|
11
|
+
"default": "./lib/lzma.js"
|
|
11
12
|
}
|
|
12
13
|
},
|
|
13
14
|
"scripts": {
|
|
14
|
-
"
|
|
15
|
+
"postinstall": "node-gyp-build",
|
|
15
16
|
"build": "tsc",
|
|
16
17
|
"build:watch": "tsc --watch",
|
|
17
18
|
"prepare": "simple-git-hooks && pnpm run build",
|
|
18
|
-
"prebuildify": "
|
|
19
|
-
"prebuildify:win": "for /f \"usebackq tokens=*\" %v in (`node -v`) do
|
|
19
|
+
"prebuildify": "prebuildify --napi --strip -t $(node -v)",
|
|
20
|
+
"prebuildify:win": "for /f \"usebackq tokens=*\" %v in (`node -v`) do prebuildify -t %v --napi --strip",
|
|
20
21
|
"test": "vitest run",
|
|
21
22
|
"test:watch": "vitest",
|
|
22
23
|
"test:coverage": "vitest run --config vitest.config.monocart.ts --coverage",
|
|
23
24
|
"test:coverage-v8": "vitest run --coverage",
|
|
25
|
+
"test:ui": "vitest --ui",
|
|
24
26
|
"type-check": "tsc --noEmit",
|
|
25
27
|
"clean": "rm -rf lib",
|
|
26
28
|
"lint": "biome lint",
|
|
@@ -30,30 +32,45 @@
|
|
|
30
32
|
"check": "biome check",
|
|
31
33
|
"check:write": "biome check --write",
|
|
32
34
|
"release": "release-it-preset default",
|
|
33
|
-
"release:manual": "release-it-preset manual
|
|
35
|
+
"release:manual": "release-it-preset --config .release-it.manual.json",
|
|
34
36
|
"release:hotfix": "release-it-preset hotfix",
|
|
35
|
-
"changelog:update": "release-it-preset changelog-only"
|
|
37
|
+
"changelog:update": "release-it-preset changelog-only",
|
|
38
|
+
"typedoc": "typedoc",
|
|
39
|
+
"typedoc:watch": "typedoc --watch"
|
|
36
40
|
},
|
|
37
41
|
"dependencies": {
|
|
38
42
|
"node-addon-api": "^8.5.0",
|
|
39
43
|
"node-gyp-build": "^4.8.4"
|
|
40
44
|
},
|
|
41
45
|
"devDependencies": {
|
|
42
|
-
"@biomejs/biome": "^2.
|
|
43
|
-
"@oorabona/release-it-preset": "^0.
|
|
46
|
+
"@biomejs/biome": "^2.3.12",
|
|
47
|
+
"@oorabona/release-it-preset": "^0.9.0",
|
|
44
48
|
"@oorabona/vitest-monocart-coverage": "^2.0.1",
|
|
45
|
-
"@types/node": "^
|
|
46
|
-
"@vitest/coverage-istanbul": "^
|
|
47
|
-
"@vitest/coverage-v8": "^
|
|
48
|
-
"@vitest/ui": "
|
|
49
|
-
"nano-staged": "^0.
|
|
50
|
-
"release-it": "^19.
|
|
49
|
+
"@types/node": "^25.0.10",
|
|
50
|
+
"@vitest/coverage-istanbul": "^4.0.18",
|
|
51
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
52
|
+
"@vitest/ui": "4.0.18",
|
|
53
|
+
"nano-staged": "^0.9.0",
|
|
54
|
+
"release-it": "^19.2.4",
|
|
51
55
|
"simple-git-hooks": "^2.13.1",
|
|
52
56
|
"tsd": "^0.33.0",
|
|
53
|
-
"
|
|
54
|
-
"
|
|
57
|
+
"typedoc": "^0.28.16",
|
|
58
|
+
"typedoc-material-theme": "^1.4.1",
|
|
59
|
+
"typescript": "^5.9.3",
|
|
60
|
+
"vitest": "^4.0.18"
|
|
55
61
|
},
|
|
56
62
|
"types": "index.d.ts",
|
|
63
|
+
"files": [
|
|
64
|
+
"lib/",
|
|
65
|
+
"src/bindings/",
|
|
66
|
+
"scripts/build_xz_with_cmake.py",
|
|
67
|
+
"scripts/download_xz_from_github.py",
|
|
68
|
+
"scripts/copy_dll.py",
|
|
69
|
+
"scripts/walk_sources.py",
|
|
70
|
+
"binding.gyp",
|
|
71
|
+
"index.d.ts",
|
|
72
|
+
"xz-version.json"
|
|
73
|
+
],
|
|
57
74
|
"engines": {
|
|
58
75
|
"node": ">=16.0.0"
|
|
59
76
|
},
|
|
@@ -282,16 +282,20 @@ def main():
|
|
|
282
282
|
parser = argparse.ArgumentParser(
|
|
283
283
|
description='Build XZ Utils using CMake',
|
|
284
284
|
epilog='''
|
|
285
|
-
|
|
286
|
-
RUNTIME_LINK: 'static' or 'shared'
|
|
287
|
-
|
|
288
|
-
|
|
285
|
+
Optional environment variables (with sensible defaults matching binding.gyp):
|
|
286
|
+
RUNTIME_LINK: 'static' or 'shared'
|
|
287
|
+
Default: 'static' on Windows, 'shared' on Linux/macOS
|
|
288
|
+
ENABLE_THREAD_SUPPORT: 'yes' or 'no'
|
|
289
|
+
Default: 'yes'
|
|
290
|
+
USE_GLOBAL: 'true' or 'false'
|
|
291
|
+
Default: 'false' on Windows, 'true' on Linux/macOS
|
|
289
292
|
|
|
290
293
|
Examples:
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
294
|
+
# Use defaults (recommended)
|
|
295
|
+
python3 build_xz_with_cmake.py deps/xz build/liblzma
|
|
296
|
+
|
|
297
|
+
# Override specific values
|
|
298
|
+
RUNTIME_LINK=static USE_GLOBAL=false \\
|
|
295
299
|
python3 build_xz_with_cmake.py deps/xz build/liblzma
|
|
296
300
|
''',
|
|
297
301
|
formatter_class=argparse.RawDescriptionHelpFormatter
|
|
@@ -304,24 +308,17 @@ Examples:
|
|
|
304
308
|
|
|
305
309
|
args = parser.parse_args()
|
|
306
310
|
|
|
307
|
-
# Get configuration from environment variables with
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
print("[ERROR] ENABLE_THREAD_SUPPORT environment variable must be explicitly set ('yes' or 'no')")
|
|
319
|
-
return 1
|
|
320
|
-
|
|
321
|
-
if use_global is None:
|
|
322
|
-
print("[ERROR] USE_GLOBAL environment variable must be explicitly set ('true' or 'false')")
|
|
323
|
-
return 1
|
|
324
|
-
|
|
311
|
+
# Get configuration from environment variables with sensible defaults
|
|
312
|
+
# Defaults match binding.gyp for consistency
|
|
313
|
+
is_windows = sys.platform == 'win32'
|
|
314
|
+
|
|
315
|
+
# Default: 'shared' on Linux/macOS, 'static' on Windows
|
|
316
|
+
runtime_link = os.environ.get('RUNTIME_LINK') or ('static' if is_windows else 'shared')
|
|
317
|
+
# Default: 'yes' (threading enabled)
|
|
318
|
+
enable_threads = os.environ.get('ENABLE_THREAD_SUPPORT') or 'yes'
|
|
319
|
+
# Default: 'false' on Windows, 'true' on Linux/macOS (use system library)
|
|
320
|
+
use_global = os.environ.get('USE_GLOBAL') or ('false' if is_windows else 'true')
|
|
321
|
+
|
|
325
322
|
# Validate values
|
|
326
323
|
if runtime_link not in ['static', 'shared']:
|
|
327
324
|
print(f"[ERROR] Invalid RUNTIME_LINK: {runtime_link}. Must be 'static' or 'shared'")
|
|
@@ -311,43 +311,44 @@ Examples:
|
|
|
311
311
|
|
|
312
312
|
# Determine version to use
|
|
313
313
|
version = determine_version()
|
|
314
|
-
|
|
315
|
-
# Validate version exists
|
|
316
|
-
validated_version = validate_version(version)
|
|
317
|
-
if not validated_version:
|
|
318
|
-
print(f"[ERROR] Version {version} not found, falling back to v5.4.0")
|
|
319
|
-
validated_version = 'v5.4.0'
|
|
320
|
-
|
|
314
|
+
|
|
321
315
|
# Prepare and validate paths
|
|
322
316
|
tarball = os.path.abspath(args.tarball)
|
|
323
317
|
dirname = os.path.abspath(args.dirname)
|
|
324
|
-
|
|
318
|
+
|
|
325
319
|
# Additional security validation for output paths
|
|
326
320
|
if not tarball or not dirname:
|
|
327
321
|
print("[ERROR] Invalid paths provided")
|
|
328
322
|
return 1
|
|
329
|
-
|
|
323
|
+
|
|
330
324
|
# Ensure paths don't contain suspicious patterns
|
|
331
325
|
suspicious_patterns = ['..', '~', '$']
|
|
332
326
|
for pattern in suspicious_patterns:
|
|
333
327
|
if pattern in args.tarball or pattern in args.dirname:
|
|
334
328
|
print(f"[ERROR] Suspicious pattern '{pattern}' detected in paths")
|
|
335
329
|
return 1
|
|
336
|
-
|
|
330
|
+
|
|
337
331
|
# Ensure we're using .tar.gz extension (GitHub uses gzip, not xz)
|
|
338
332
|
if tarball.endswith('.tar.xz'):
|
|
339
333
|
tarball = tarball.replace('.tar.xz', '.tar.gz')
|
|
340
334
|
print(f"[NOTE] Adjusted tarball name to: {tarball}")
|
|
341
|
-
|
|
335
|
+
|
|
342
336
|
# Create directories if needed
|
|
343
337
|
os.makedirs(os.path.dirname(tarball), exist_ok=True)
|
|
344
338
|
os.makedirs(dirname, exist_ok=True)
|
|
345
339
|
|
|
346
340
|
# Check if already extracted with correct version (smart cache)
|
|
347
|
-
|
|
348
|
-
|
|
341
|
+
# Do this BEFORE any GitHub API calls to avoid rate limiting
|
|
342
|
+
if is_xz_already_extracted(dirname, version):
|
|
343
|
+
print(f"[SKIP] XZ {version} already available, skipping download")
|
|
349
344
|
return 0
|
|
350
345
|
|
|
346
|
+
# Only validate version if we need to download (avoids GitHub API call when cached)
|
|
347
|
+
validated_version = validate_version(version)
|
|
348
|
+
if not validated_version:
|
|
349
|
+
print(f"[ERROR] Version {version} not found, falling back to v5.4.0")
|
|
350
|
+
validated_version = 'v5.4.0'
|
|
351
|
+
|
|
351
352
|
# Download if not cached
|
|
352
353
|
if os.path.exists(tarball):
|
|
353
354
|
print(f"[CACHED] Using cached tarball: {tarball}")
|
|
@@ -29,6 +29,12 @@ Napi::Value LZMA::Close(const Napi::CallbackInfo &info)
|
|
|
29
29
|
|
|
30
30
|
Napi::Value LZMA::Close(const Napi::Env &env)
|
|
31
31
|
{
|
|
32
|
+
// F-006: Idempotency guard - prevent double-subtract of external memory
|
|
33
|
+
if (_closed)
|
|
34
|
+
{
|
|
35
|
+
return env.Undefined();
|
|
36
|
+
}
|
|
37
|
+
_closed = true;
|
|
32
38
|
Napi::MemoryManagement::AdjustExternalMemory(env, -int64_t(sizeof(LZMA)));
|
|
33
39
|
|
|
34
40
|
if (_wip)
|
|
@@ -63,7 +69,7 @@ void LZMA::Init(Napi::Env env, Napi::Object exports)
|
|
|
63
69
|
}
|
|
64
70
|
|
|
65
71
|
LZMA::LZMA(const Napi::CallbackInfo &info) : Napi::ObjectWrap<LZMA>(info), _stream(LZMA_STREAM_INIT),
|
|
66
|
-
_wip(false), _pending_close(false), _worker(nullptr)
|
|
72
|
+
_wip(false), _pending_close(false), _closed(false), _worker(nullptr)
|
|
67
73
|
{
|
|
68
74
|
Napi::Env env = info.Env();
|
|
69
75
|
|
|
@@ -103,7 +109,7 @@ LZMA::LZMA(const Napi::CallbackInfo &info) : Napi::ObjectWrap<LZMA>(info), _stre
|
|
|
103
109
|
switch (mode)
|
|
104
110
|
{
|
|
105
111
|
case STREAM_DECODE:
|
|
106
|
-
success = InitializeDecoder();
|
|
112
|
+
success = InitializeDecoder(env);
|
|
107
113
|
break;
|
|
108
114
|
case STREAM_ENCODE:
|
|
109
115
|
success = InitializeEncoder(opts, preset, check);
|
|
@@ -163,6 +169,13 @@ LZMA::~LZMA()
|
|
|
163
169
|
template <bool async>
|
|
164
170
|
Napi::Value LZMA::Code(const Napi::CallbackInfo &info)
|
|
165
171
|
{
|
|
172
|
+
// F-001: Guard against concurrent calls - liblzma is not thread-safe per stream
|
|
173
|
+
if (this->_wip)
|
|
174
|
+
{
|
|
175
|
+
Napi::Error::New(info.Env(), "Stream is busy - concurrent operations not allowed").ThrowAsJavaScriptException();
|
|
176
|
+
return info.Env().Undefined();
|
|
177
|
+
}
|
|
178
|
+
|
|
166
179
|
// Setup with manual guard (safer than RAII for JS exceptions)
|
|
167
180
|
this->_wip = true;
|
|
168
181
|
this->Ref();
|
|
@@ -285,6 +298,14 @@ bool LZMA::ValidateAndPrepareBuffers(const Napi::CallbackInfo &info, BufferConte
|
|
|
285
298
|
}
|
|
286
299
|
|
|
287
300
|
ctx.out_off = info[5].ToNumber().Uint32Value();
|
|
301
|
+
|
|
302
|
+
// F-002: Validate output offset bounds to prevent underflow in out_len calculation
|
|
303
|
+
if (ctx.out_off > out_max)
|
|
304
|
+
{
|
|
305
|
+
Napi::RangeError::New(env, "Output offset exceeds buffer length").ThrowAsJavaScriptException();
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
|
|
288
309
|
ctx.out_len = out_max - ctx.out_off;
|
|
289
310
|
ctx.out = out_buf + ctx.out_off;
|
|
290
311
|
|
|
@@ -461,10 +482,18 @@ bool LZMA::InitializeEncoder(const Napi::Object &opts, uint32_t preset, lzma_che
|
|
|
461
482
|
return true;
|
|
462
483
|
}
|
|
463
484
|
|
|
464
|
-
bool LZMA::InitializeDecoder()
|
|
485
|
+
bool LZMA::InitializeDecoder(const Napi::Env &env)
|
|
465
486
|
{
|
|
466
487
|
lzma_ret ret = lzma_stream_decoder(&this->_stream, UINT64_MAX, LZMA_CONCATENATED);
|
|
467
|
-
|
|
488
|
+
|
|
489
|
+
// F-005: Throw exception on decoder init failure (consistent with InitializeEncoder)
|
|
490
|
+
if (ret != LZMA_OK)
|
|
491
|
+
{
|
|
492
|
+
Napi::Error::New(env, "LZMA decoder failure, returned " + std::to_string(ret)).ThrowAsJavaScriptException();
|
|
493
|
+
return false;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
return true;
|
|
468
497
|
}
|
|
469
498
|
|
|
470
499
|
void LZMA::AfterCommon(const Napi::Env &env)
|
|
@@ -515,8 +544,15 @@ void LZMA::After(const Napi::Env &env, const Napi::Function &cb)
|
|
|
515
544
|
Napi::Number avail_in = Napi::Number::New(env, this->_stream.avail_in);
|
|
516
545
|
Napi::Number avail_out = Napi::Number::New(env, this->_stream.avail_out);
|
|
517
546
|
|
|
547
|
+
// F-001: Clear _wip BEFORE callback so callback can call code() again for iterative processing
|
|
548
|
+
// Note: Buffer refs are released after callback in case callback needs to access them
|
|
549
|
+
this->_wip = false;
|
|
550
|
+
|
|
518
551
|
// Call the provided JS callback with the three numeric results
|
|
552
|
+
// The callback may call code() again for iterative processing (this is the normal pattern)
|
|
519
553
|
cb.Call({ret, avail_in, avail_out});
|
|
520
554
|
|
|
555
|
+
// F-004: Ensure cleanup runs even if callback threw an exception
|
|
556
|
+
// With NAPI_DISABLE_CPP_EXCEPTIONS, exceptions are pending rather than thrown
|
|
521
557
|
AfterCommon(env);
|
|
522
558
|
}
|
|
@@ -81,7 +81,7 @@ private:
|
|
|
81
81
|
bool ValidateConstructorArgs(const Napi::CallbackInfo &info, uint32_t &mode, Napi::Object &opts);
|
|
82
82
|
bool InitializeFilters(const Napi::Object &opts, uint32_t preset);
|
|
83
83
|
bool InitializeEncoder(const Napi::Object &opts, uint32_t preset, lzma_check check);
|
|
84
|
-
bool InitializeDecoder();
|
|
84
|
+
bool InitializeDecoder(const Napi::Env &env);
|
|
85
85
|
|
|
86
86
|
// Common cleanup operations for both sync and async completion
|
|
87
87
|
void AfterCommon(const Napi::Env &env);
|
|
@@ -95,6 +95,7 @@ private:
|
|
|
95
95
|
lzma_stream _stream;
|
|
96
96
|
bool _wip;
|
|
97
97
|
bool _pending_close;
|
|
98
|
+
bool _closed; // F-006: Prevent double-subtract in AdjustExternalMemory
|
|
98
99
|
|
|
99
100
|
LZMAWorker *_worker;
|
|
100
101
|
|
package/xz-version.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "v5.8.
|
|
3
|
-
"comment": "
|
|
4
|
-
"last_checked": "
|
|
2
|
+
"version": "v5.8.2",
|
|
3
|
+
"comment": "Stable version tested and validated for production. Auto-updated by GitHub Actions.",
|
|
4
|
+
"last_checked": "2026-01-25",
|
|
5
5
|
"allow_override": true,
|
|
6
6
|
"repository": "tukaani-project/xz",
|
|
7
7
|
"changelog": "https://github.com/tukaani-project/xz/releases/tag/v5.8.1"
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"permissions": {
|
|
3
|
-
"allow": [
|
|
4
|
-
"Bash(node:*)",
|
|
5
|
-
"WebSearch",
|
|
6
|
-
"Bash(npm run build:*)",
|
|
7
|
-
"Bash(pnpm install:*)",
|
|
8
|
-
"Bash(pnpm run:*)",
|
|
9
|
-
"Bash(pnpm add:*)",
|
|
10
|
-
"Bash(pnpm test:*)",
|
|
11
|
-
"Bash(xz:*)",
|
|
12
|
-
"Bash(pnpm exec:*)",
|
|
13
|
-
"Bash(pnpm lint:*)",
|
|
14
|
-
"Bash(pnpm check:write:*)",
|
|
15
|
-
"Bash(pnpm build:*)",
|
|
16
|
-
"Bash(pnpm type-check:*)",
|
|
17
|
-
"Bash(pnpm check:*)",
|
|
18
|
-
"Bash(pnpm format:write:*)",
|
|
19
|
-
"Bash(pnpm tsc:*)",
|
|
20
|
-
"Bash(sed:*)",
|
|
21
|
-
"Bash(grep:*)",
|
|
22
|
-
"WebFetch(domain:github.com)",
|
|
23
|
-
"Bash(git rm:*)",
|
|
24
|
-
"Bash(git add:*)",
|
|
25
|
-
"WebFetch(domain:api.github.com)",
|
|
26
|
-
"Bash(python3:*)",
|
|
27
|
-
"Bash(chmod:*)",
|
|
28
|
-
"WebFetch(domain:raw.githubusercontent.com)",
|
|
29
|
-
"Bash(cmake:*)",
|
|
30
|
-
"Bash(USE_GLOBAL=false RUNTIME_LINK=static ENABLE_THREAD_SUPPORT=yes pnpm install)",
|
|
31
|
-
"Bash(gh act:*)",
|
|
32
|
-
"Bash(npx node-gyp:*)",
|
|
33
|
-
"Bash(USE_GLOBAL=false RUNTIME_LINK=static ENABLE_THREAD_SUPPORT=no pnpm install --frozen-lockfile)",
|
|
34
|
-
"Bash(USE_GLOBAL=false RUNTIME_LINK=shared ENABLE_THREAD_SUPPORT=yes pnpm install --frozen-lockfile)",
|
|
35
|
-
"mcp__github__get_job_logs",
|
|
36
|
-
"Bash(XZ_VERSION=v5.4.0 python3 scripts/download_xz_from_github.py /tmp/test_xz.tar.gz /tmp/test_extract --verbose)",
|
|
37
|
-
"Bash(RUNTIME_LINK=shared node -p \"process.env.RUNTIME_LINK || ''static''\")",
|
|
38
|
-
"Bash(RUNTIME_LINK=shared rm -rf build/Release deps)",
|
|
39
|
-
"Bash(USE_GLOBAL=false RUNTIME_LINK=shared rm -rf build/Release deps prebuilds)",
|
|
40
|
-
"Bash(pnpm rebuild:*)",
|
|
41
|
-
"Bash(RUNTIME_LINK=shared ENABLE_THREAD_SUPPORT=yes python3 scripts/build_xz_with_cmake.py --help)",
|
|
42
|
-
"Bash(gh run view:*)",
|
|
43
|
-
"Bash(RUNTIME_LINK=shared ENABLE_THREAD_SUPPORT=yes python3 scripts/build_xz_with_cmake.py deps/xz build/liblzma_test --verbose)",
|
|
44
|
-
"Bash(USE_GLOBAL=true pnpm test)",
|
|
45
|
-
"Bash(RUNTIME_LINK=shared ENABLE_THREAD_SUPPORT=no USE_GLOBAL=false pnpm run build)",
|
|
46
|
-
"Bash(RUNTIME_LINK=shared ENABLE_THREAD_SUPPORT=yes USE_GLOBAL=false python3 scripts/build_xz_with_cmake.py /tmp/test_cmake /tmp/test_install --verbose)",
|
|
47
|
-
"Bash(npx tsc:*)",
|
|
48
|
-
"Bash(yamllint:*)",
|
|
49
|
-
"Bash(./test-ci-logic.sh:*)",
|
|
50
|
-
"Bash(find:*)",
|
|
51
|
-
"Read(/tmp/**)",
|
|
52
|
-
"Read(/tmp/**)",
|
|
53
|
-
"Read(/tmp/**)",
|
|
54
|
-
"Read(/tmp/**)",
|
|
55
|
-
"Bash(USE_GLOBAL=false RUNTIME_LINK=static ENABLE_THREAD_SUPPORT=yes pnpm install --frozen-lockfile)",
|
|
56
|
-
"Bash(USE_GLOBAL=false RUNTIME_LINK=static ENABLE_THREAD_SUPPORT=yes rm -rf build/Release deps)",
|
|
57
|
-
"Bash(USE_GLOBAL=false RUNTIME_LINK=static ENABLE_THREAD_SUPPORT=yes rm -rf build/Release)",
|
|
58
|
-
"Bash(USE_GLOBAL=false RUNTIME_LINK=static ENABLE_THREAD_SUPPORT=no rm -rf build/Release)",
|
|
59
|
-
"Bash(USE_GLOBAL=false RUNTIME_LINK=static ENABLE_THREAD_SUPPORT=no pnpm rebuild)",
|
|
60
|
-
"WebFetch(domain:www.npmjs.com)",
|
|
61
|
-
"Bash(xargs ls:*)",
|
|
62
|
-
"Bash(pnpm vitest run:*)",
|
|
63
|
-
"Bash(pnpm outdated:*)",
|
|
64
|
-
"Bash(pnpm audit:*)",
|
|
65
|
-
"Bash(pnpm test:coverage:*)",
|
|
66
|
-
"Bash(cat:*)",
|
|
67
|
-
"mcp__github__get_workflow_run",
|
|
68
|
-
"mcp__github__list_workflow_runs",
|
|
69
|
-
"mcp__github__list_workflows",
|
|
70
|
-
"Bash(gh run list:*)",
|
|
71
|
-
"Bash(node-gyp rebuild:*)",
|
|
72
|
-
"Bash(USE_GLOBAL=true RUNTIME_LINK=shared ENABLE_THREAD_SUPPORT=yes pnpm rebuild)",
|
|
73
|
-
"Bash(export USE_GLOBAL=true RUNTIME_LINK=shared ENABLE_THREAD_SUPPORT=yes)",
|
|
74
|
-
"Bash(npm:*)",
|
|
75
|
-
"Bash(pnpm list:*)",
|
|
76
|
-
"Read(//home/o2/.cache/node-gyp/22.15.0/include/node/**)",
|
|
77
|
-
"Bash(pkg-config:*)",
|
|
78
|
-
"Bash(g++:*)",
|
|
79
|
-
"Read(//home/o2/.cache/node-gyp/22.15.0/**)",
|
|
80
|
-
"Read(//tmp/**)",
|
|
81
|
-
"mcp__github__list_workflow_jobs",
|
|
82
|
-
"Bash(otool:*)",
|
|
83
|
-
"Bash(git log:*)",
|
|
84
|
-
"mcp__github__get_me",
|
|
85
|
-
"mcp__github__list_tags",
|
|
86
|
-
"mcp__github__get_commit",
|
|
87
|
-
"mcp__github__get_file_contents"
|
|
88
|
-
],
|
|
89
|
-
"deny": [],
|
|
90
|
-
"ask": []
|
|
91
|
-
}
|
|
92
|
-
}
|
package/.gitattributes
DELETED