pdfium-native 0.5.6 → 0.6.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.
- package/CHANGELOG.md +75 -17
- package/README.md +4 -3
- package/THIRD-PARTY-NOTICES.md +47 -0
- package/binding.gyp +7 -4
- package/dist/concurrency.js +1 -1
- package/dist/concurrency.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/page.d.ts.map +1 -1
- package/dist/page.js +2 -1
- package/dist/page.js.map +1 -1
- package/lib/index.ts +3 -1
- package/lib/page.ts +4 -3
- package/package.json +17 -10
- package/scripts/download-pdfium.mjs +19 -43
- package/scripts/gen-prebuild-manifest.mjs +59 -0
- package/scripts/install.mjs +35 -4
- package/scripts/lib/integrity.mjs +129 -0
- package/scripts/native-deps.json +50 -0
- package/scripts/prebuilds.json +12 -0
- package/scripts/update-native-deps.mjs +129 -0
- package/scripts/verify-checksums.mjs +58 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,58 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/), and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [0.6.1] - 2026-07-15
|
|
10
|
+
|
|
11
|
+
### Security
|
|
12
|
+
|
|
13
|
+
- Verify the downloaded prebuilt binary against a per-platform SHA-256 pin shipped in the package before use, falling back to the checksum-pinned source build on mismatch or a missing pin. Closes the prebuilt-binary trust gap where a swapped GitHub release asset could be executed unverified.
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- The `update-native-deps` PR body now describes `verify-checksums` as a consistency check against the same source rather than "independent" verification.
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- Hermetic test coverage for prebuilt verification and manifest generation (`test/prebuild.test.ts`).
|
|
22
|
+
|
|
23
|
+
## [0.6.0] - 2026-06-27
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
|
|
27
|
+
- `.nvmrc` and a `packageManager` field to pin the development toolchain
|
|
28
|
+
- `.editorconfig` for consistent cross-editor defaults
|
|
29
|
+
- Vitest v8 coverage reporting (`npm run test:coverage`)
|
|
30
|
+
- `typecheck` step wired into CI (`npm run typecheck`) for type-level regression coverage
|
|
31
|
+
- Weekly `windows-latest` canary workflow to detect drift from the pinned `windows-2022` runner
|
|
32
|
+
- `"./package.json"` to the package `exports` map
|
|
33
|
+
|
|
34
|
+
### Changed
|
|
35
|
+
|
|
36
|
+
- Raised the minimum supported Node.js to `>=22.0.0` (dropped EOL Node 20)
|
|
37
|
+
- TypeScript config: `nodenext` module resolution, `es2023` target, and stricter flags (`verbatimModuleSyntax`, `exactOptionalPropertyTypes`, `noUnusedLocals`, `noUnusedParameters`, `noImplicitOverride`, `noFallthroughCasesInSwitch`)
|
|
38
|
+
- ESLint: type-aware linting for `lib/`, adopted the `globals` package, and dropped `eslint-plugin-prettier`
|
|
39
|
+
- Native build: bumped the C++ standard to C++20 and Node-API to 9 (C++ standard now defined once via a gyp variable)
|
|
40
|
+
- CI/CD hardening: pinned all GitHub Actions to commit SHAs, added npm and native-dependency caching, a concurrency group, job timeouts, and top-level least-privilege permissions
|
|
41
|
+
|
|
42
|
+
### Security
|
|
43
|
+
|
|
44
|
+
- Added OpenSSF Scorecard analysis, Dependabot, and a security policy (`SECURITY.md`); CodeQL code scanning runs via GitHub's default setup
|
|
45
|
+
- Supply chain: pin and verify the SHA-256 of every downloaded native dependency (`scripts/native-deps.json`) through a hardened downloader (timeout, retry, atomic writes, origin pinning); added an `npm run verify:checksums` tripwire
|
|
46
|
+
|
|
47
|
+
### Fixed
|
|
48
|
+
|
|
49
|
+
- Windows build: upgraded `node-gyp` to 13 and dropped Node 20 from the CI matrix
|
|
50
|
+
- Pinned Windows CI to `windows-2022` to avoid a VS 2026 (MSVC C1001) internal compiler error
|
|
51
|
+
|
|
52
|
+
## [0.5.6] - 2026-06-26
|
|
53
|
+
|
|
54
|
+
### Fixed
|
|
55
|
+
|
|
56
|
+
- Fix double free of addon instance data on environment teardown
|
|
57
|
+
- `npm audit` fix for transitive dev dependencies
|
|
58
|
+
|
|
7
59
|
## [0.5.5] - 2026-04-26
|
|
8
60
|
|
|
9
61
|
### Changed
|
|
@@ -80,23 +132,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/), and this
|
|
|
80
132
|
- Image `render()` binding moved from TypeScript layer to native C++ (`GetObjectWorker::OnOK`) for cleaner API
|
|
81
133
|
- `PDFiumPage.getObject()` is now a direct passthrough to the native addon
|
|
82
134
|
|
|
83
|
-
## [0.3.0] - 2026-03-31
|
|
84
|
-
|
|
85
|
-
### Added
|
|
86
|
-
|
|
87
|
-
- `ImagePageObject.render()` — extract and render embedded PDF images as PNG, JPEG, or raw stream bytes
|
|
88
|
-
- Three render modes: intrinsic bitmap, rendered bitmap (with mask/matrix), and raw encoded stream
|
|
89
|
-
- File output support for image rendering via `output` option
|
|
90
|
-
- `objects()` async generator on `PDFiumPage` for iterating all page objects
|
|
91
|
-
- Image dimension cap (`MAX_IMAGE_PIXELS = 256 MP`) to prevent allocation failures on huge embedded images
|
|
92
|
-
- Negative object index guard in `RenderImageWorker`
|
|
93
|
-
|
|
94
|
-
### Changed
|
|
95
|
-
|
|
96
|
-
- **Breaking:** Default render format changed from JPEG to PNG for both `page.render()` and `image.render()` — use `{ format: 'jpeg' }` to restore previous behavior
|
|
97
|
-
- Image `render()` binding moved from TypeScript layer to native C++ (`GetObjectWorker::OnOK`) for cleaner API
|
|
98
|
-
- `PDFiumPage.getObject()` is now a direct passthrough to the native addon
|
|
99
|
-
|
|
100
135
|
## [0.2.4] - 2026-03-30
|
|
101
136
|
|
|
102
137
|
### Fixed
|
|
@@ -250,3 +285,26 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/), and this
|
|
|
250
285
|
- ESLint + Prettier configuration
|
|
251
286
|
- GitHub Actions publish workflow with test gate
|
|
252
287
|
- TypeScript type declarations for JS consumers
|
|
288
|
+
|
|
289
|
+
[Unreleased]: https://github.com/xonaman/nodejs-pdfium-native/compare/v0.6.1...HEAD
|
|
290
|
+
[0.6.1]: https://github.com/xonaman/nodejs-pdfium-native/compare/v0.6.0...v0.6.1
|
|
291
|
+
[0.6.0]: https://github.com/xonaman/nodejs-pdfium-native/compare/v0.5.6...v0.6.0
|
|
292
|
+
[0.5.6]: https://github.com/xonaman/nodejs-pdfium-native/compare/v0.5.5...v0.5.6
|
|
293
|
+
[0.5.5]: https://github.com/xonaman/nodejs-pdfium-native/compare/v0.5.4...v0.5.5
|
|
294
|
+
[0.5.4]: https://github.com/xonaman/nodejs-pdfium-native/compare/v0.5.3...v0.5.4
|
|
295
|
+
[0.5.3]: https://github.com/xonaman/nodejs-pdfium-native/compare/v0.5.2...v0.5.3
|
|
296
|
+
[0.5.2]: https://github.com/xonaman/nodejs-pdfium-native/compare/v0.5.1...v0.5.2
|
|
297
|
+
[0.5.1]: https://github.com/xonaman/nodejs-pdfium-native/compare/v0.5.0...v0.5.1
|
|
298
|
+
[0.5.0]: https://github.com/xonaman/nodejs-pdfium-native/compare/v0.4.0...v0.5.0
|
|
299
|
+
[0.4.0]: https://github.com/xonaman/nodejs-pdfium-native/compare/v0.3.0...v0.4.0
|
|
300
|
+
[0.3.0]: https://github.com/xonaman/nodejs-pdfium-native/compare/v0.2.4...v0.3.0
|
|
301
|
+
[0.2.4]: https://github.com/xonaman/nodejs-pdfium-native/compare/v0.2.3...v0.2.4
|
|
302
|
+
[0.2.3]: https://github.com/xonaman/nodejs-pdfium-native/compare/v0.2.2...v0.2.3
|
|
303
|
+
[0.2.2]: https://github.com/xonaman/nodejs-pdfium-native/compare/v0.2.0...v0.2.2
|
|
304
|
+
[0.2.0]: https://github.com/xonaman/nodejs-pdfium-native/compare/v0.1.7...v0.2.0
|
|
305
|
+
[0.1.7]: https://github.com/xonaman/nodejs-pdfium-native/compare/v0.1.6...v0.1.7
|
|
306
|
+
[0.1.6]: https://github.com/xonaman/nodejs-pdfium-native/compare/v0.1.5...v0.1.6
|
|
307
|
+
[0.1.5]: https://github.com/xonaman/nodejs-pdfium-native/compare/v0.1.4...v0.1.5
|
|
308
|
+
[0.1.4]: https://github.com/xonaman/nodejs-pdfium-native/compare/0.1.3...v0.1.4
|
|
309
|
+
[0.1.3]: https://github.com/xonaman/nodejs-pdfium-native/compare/0.1.2...0.1.3
|
|
310
|
+
[0.1.2]: https://github.com/xonaman/nodejs-pdfium-native/releases/tag/0.1.2
|
package/README.md
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
# pdfium-native
|
|
2
2
|
|
|
3
|
+
[](https://github.com/xonaman/nodejs-pdfium-native/actions/workflows/ci.yml)
|
|
3
4
|
[](https://www.npmjs.com/package/pdfium-native)
|
|
4
5
|
[](https://nodejs.org)
|
|
5
6
|
[](https://github.com/xonaman/nodejs-pdfium-native/blob/main/LICENSE)
|
|
6
|
-
[]()
|
|
7
|
+
[](#-supported-platforms)
|
|
7
8
|
|
|
8
9
|
Fast, native PDF rendering and text extraction for Node.js — powered by [PDFium](https://pdfium.googlesource.com/pdfium/), the same engine used in Chromium. Built as a C++ addon with N-API for ABI stability across Node.js versions.
|
|
9
10
|
|
|
@@ -40,7 +41,7 @@ doc.destroy();
|
|
|
40
41
|
**🔒 Reliability**
|
|
41
42
|
|
|
42
43
|
- Built on PDFium — the PDF engine used in Chromium
|
|
43
|
-
- ABI-stable via N-API — works across Node.js
|
|
44
|
+
- ABI-stable via N-API — works across Node.js 22–24 without recompilation
|
|
44
45
|
- Password-protected PDFs supported out of the box
|
|
45
46
|
|
|
46
47
|
### 🎯 Use cases
|
|
@@ -90,7 +91,7 @@ doc.destroy();
|
|
|
90
91
|
npm install pdfium-native
|
|
91
92
|
```
|
|
92
93
|
|
|
93
|
-
Prebuilt binaries are available for all [supported platforms](
|
|
94
|
+
Prebuilt binaries are available for all [supported platforms](#-supported-platforms) — most installs require no compiler. If no prebuilt is available, the package falls back to compiling from source (requires a C++ toolchain: Xcode CLI tools on macOS, `build-essential` on Linux, Visual Studio on Windows).
|
|
94
95
|
|
|
95
96
|
## 🌍 Supported Platforms
|
|
96
97
|
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Third-Party Notices
|
|
2
|
+
|
|
3
|
+
`pdfium-native` is distributed under the [MIT License](./LICENSE). It bundles
|
|
4
|
+
and/or links against the third-party native components listed below. Each
|
|
5
|
+
component remains under its own license; the relevant license texts are shipped
|
|
6
|
+
inside the prebuilt PDFium distribution under `deps/pdfium/licenses/`.
|
|
7
|
+
|
|
8
|
+
## Bundled native libraries
|
|
9
|
+
|
|
10
|
+
| Component | Version | License |
|
|
11
|
+
| -------------------------------------------------- | --------------- | --------------------------------------- |
|
|
12
|
+
| [PDFium](https://pdfium.googlesource.com/pdfium/) | `chromium/7749` | BSD-3-Clause |
|
|
13
|
+
| [stb_image_write](https://github.com/nothings/stb) | `v1.16` | Public Domain (Unlicense) or MIT (dual) |
|
|
14
|
+
|
|
15
|
+
- **PDFium** — the PDF rendering and parsing engine, consumed as a prebuilt
|
|
16
|
+
shared library from
|
|
17
|
+
[bblanchon/pdfium-binaries](https://github.com/bblanchon/pdfium-binaries).
|
|
18
|
+
Copyright The PDFium Authors. Licensed under BSD-3-Clause.
|
|
19
|
+
- **stb_image_write** — single-header PNG/JPEG encoder vendored in
|
|
20
|
+
`src/stb_image_write.{h,cc}`, used to encode rendered bitmaps. By Sean Barrett
|
|
21
|
+
(and based on Jon Olick's public-domain JPEG writer). Dual-licensed: you may
|
|
22
|
+
use it under the MIT License or as public domain (Unlicense).
|
|
23
|
+
|
|
24
|
+
## Components statically linked into the prebuilt PDFium library
|
|
25
|
+
|
|
26
|
+
The prebuilt PDFium shared library statically incorporates the third-party
|
|
27
|
+
components below. Their versions track the upstream PDFium `chromium/7749`
|
|
28
|
+
build; full license texts are provided in `deps/pdfium/licenses/`.
|
|
29
|
+
|
|
30
|
+
| Component | License |
|
|
31
|
+
| ------------------------- | ----------------------------------------- |
|
|
32
|
+
| Abseil | Apache-2.0 |
|
|
33
|
+
| Anti-Grain Geometry (2.3) | Anti-Grain Geometry License (permissive) |
|
|
34
|
+
| fast_float | MIT (also Apache-2.0 / BSL-1.0) |
|
|
35
|
+
| FreeType | FreeType License (FTL) or GPLv2 |
|
|
36
|
+
| ICU | Unicode License v3 |
|
|
37
|
+
| Little CMS (lcms2) | MIT |
|
|
38
|
+
| libjpeg-turbo | BSD-3-Clause and IJG License |
|
|
39
|
+
| OpenJPEG | BSD-2-Clause |
|
|
40
|
+
| libpng | libpng License (PNG Reference Library v2) |
|
|
41
|
+
| libtiff | libtiff License (MIT/BSD-style) |
|
|
42
|
+
| LLVM libc | Apache-2.0 with LLVM Exceptions |
|
|
43
|
+
| simdutf | MIT (also Apache-2.0) |
|
|
44
|
+
| zlib (1.3.1) | zlib License |
|
|
45
|
+
|
|
46
|
+
If you redistribute `pdfium-native` (or its prebuilt binaries), you must retain
|
|
47
|
+
the above notices and the corresponding license texts.
|
package/binding.gyp
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
"targets": [
|
|
3
3
|
{
|
|
4
4
|
"target_name": "pdfium",
|
|
5
|
+
"variables": {
|
|
6
|
+
"cpp_std%": "c++20"
|
|
7
|
+
},
|
|
5
8
|
"sources": [
|
|
6
9
|
"src/pdfium_addon.cc",
|
|
7
10
|
"src/stb_image_write.cc"
|
|
@@ -12,7 +15,7 @@
|
|
|
12
15
|
"src"
|
|
13
16
|
],
|
|
14
17
|
"defines": [
|
|
15
|
-
"NAPI_VERSION=
|
|
18
|
+
"NAPI_VERSION=9"
|
|
16
19
|
],
|
|
17
20
|
"cflags!": [
|
|
18
21
|
"-fno-exceptions"
|
|
@@ -27,7 +30,7 @@
|
|
|
27
30
|
"-fno-exceptions"
|
|
28
31
|
],
|
|
29
32
|
"cflags_cc": [
|
|
30
|
-
"-std
|
|
33
|
+
"-std=<(cpp_std)",
|
|
31
34
|
"-fvisibility=hidden"
|
|
32
35
|
],
|
|
33
36
|
"conditions": [
|
|
@@ -36,7 +39,7 @@
|
|
|
36
39
|
{
|
|
37
40
|
"xcode_settings": {
|
|
38
41
|
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
|
|
39
|
-
"CLANG_CXX_LANGUAGE_STANDARD": "
|
|
42
|
+
"CLANG_CXX_LANGUAGE_STANDARD": "<(cpp_std)",
|
|
40
43
|
"GCC_SYMBOLS_PRIVATE_EXTERN": "YES",
|
|
41
44
|
"DEAD_CODE_STRIPPING": "YES",
|
|
42
45
|
"LLVM_LTO": "YES",
|
|
@@ -85,7 +88,7 @@
|
|
|
85
88
|
"Optimization": 2,
|
|
86
89
|
"WholeProgramOptimization": "true",
|
|
87
90
|
"AdditionalOptions": [
|
|
88
|
-
"/std
|
|
91
|
+
"/std:<(cpp_std)"
|
|
89
92
|
]
|
|
90
93
|
},
|
|
91
94
|
"VCLinkerTool": {
|
package/dist/concurrency.js
CHANGED
package/dist/concurrency.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"concurrency.js","sourceRoot":"","sources":["../lib/concurrency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,
|
|
1
|
+
{"version":3,"file":"concurrency.js","sourceRoot":"","sources":["../lib/concurrency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,MAAM,EAAE,EAAsB,MAAM,SAAS,CAAC;AAErD,IAAI,KAAK,GAAkB,MAAM,CAAC,oBAAoB,EAAE,CAAC,CAAC;AAE1D;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YAC1C,MAAM,IAAI,SAAS,CAAC,4CAA4C,CAAC,CAAC;QACpE,CAAC;QACD,KAAK,GAAG,MAAM,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,oBAAoB,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,KAAK,CAAC,WAAW,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,eAAe,CAAI,EAAoB;IACrD,OAAO,KAAK,CAAC,EAAE,CAAC,CAAC;AACnB,CAAC"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EAErB,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAKpB,KAAK,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EAErB,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAKpB,KAAK,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAgBhC;;GAEG;AACH,wBAAsB,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAM9F;AAED;;;GAGG;AACH,wBAAsB,aAAa,CACjC,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,EAAE,oBAAoB,GAAG;IAAE,OAAO,EAAE,MAAM,EAAE,CAAA;CAA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|
else {
|
|
17
17
|
process.env.LD_LIBRARY_PATH = `${addonDir}:${process.env.LD_LIBRARY_PATH ?? ''}`;
|
|
18
18
|
}
|
|
19
|
+
// The native addon is loaded through createRequire, so its export is `any` at
|
|
20
|
+
// the module boundary; assert it to the typed surface once, here.
|
|
19
21
|
const addon = require('../build/Release/pdfium.node');
|
|
20
22
|
/**
|
|
21
23
|
* Opens a PDF document from a Buffer or file path.
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAQ/C,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAI1D,oEAAoE;AACpE,uEAAuE;AACvE,kEAAkE;AAClE,MAAM,QAAQ,GAAG,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;AAC9D,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;IACjC,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;AAC7D,CAAC;KAAM,CAAC;IACN,OAAO,CAAC,GAAG,CAAC,eAAe,GA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IACjE,OAAO,IAAI,cAAc,CAAC,UAAU,CAAC;IAM5C,2CAA2C;IAC3C,KAAK,IAAI,IAAI;IAIb,qCAAqC;IACrC,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAI3B,wFAAwF;IACxF,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAIrE,2CAA2C;IAC3C,cAAc,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IAIvC,2CAA2C;IAC3C,aAAa,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;CAGtC"}
|
package/dist/page.js
CHANGED
|
@@ -48,7 +48,8 @@ export class PDFiumPage {
|
|
|
48
48
|
/** Returns the page object at the given index with type and bounds. */
|
|
49
49
|
async getObject(index) {
|
|
50
50
|
const obj = await withConcurrency(() => this.native.getObject(index));
|
|
51
|
-
// wrap the native render function on image objects with the concurrency
|
|
51
|
+
// wrap the native render function on image objects with the concurrency
|
|
52
|
+
// semaphore. `obj` is already narrowed to ImagePageObject by the guard.
|
|
52
53
|
if (obj.type === 'image') {
|
|
53
54
|
const nativeRender = obj.render.bind(obj);
|
|
54
55
|
obj.render = ((opts) => withConcurrency(() => nativeRender(opts)));
|
package/dist/page.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page.js","sourceRoot":"","sources":["../lib/page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAenD;;GAEG;AACH,MAAM,OAAO,UAAU;IAqBD;IApBpB,+CAA+C;IACtC,KAAK,CAAS;IACvB,gDAAgD;IACvC,MAAM,CAAS;IACxB,0BAA0B;IACjB,MAAM,CAAS;IACxB,gEAAgE;IACvD,WAAW,CAAS;IAC7B,kEAAkE;IACzD,QAAQ,CAAS;IAC1B,yCAAyC;IAChC,eAAe,CAAU;IAClC,2FAA2F;IAClF,KAAK,CAAU;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,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IAClE,CAAC;IAED,2CAA2C;IAC3C,cAAc;QACZ,OAAO,eAAe,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED,2CAA2C;IAC3C,aAAa;QACX,OAAO,eAAe,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC,CAAC;IAC5D,CAAC;CACF"}
|
package/lib/index.ts
CHANGED
|
@@ -26,7 +26,9 @@ if (process.platform === 'win32') {
|
|
|
26
26
|
process.env.LD_LIBRARY_PATH = `${addonDir}:${process.env.LD_LIBRARY_PATH ?? ''}`;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
// The native addon is loaded through createRequire, so its export is `any` at
|
|
30
|
+
// the module boundary; assert it to the typed surface once, here.
|
|
31
|
+
const addon = require('../build/Release/pdfium.node') as NativeAddon;
|
|
30
32
|
|
|
31
33
|
/**
|
|
32
34
|
* Opens a PDF document from a Buffer or file path.
|
package/lib/page.ts
CHANGED
|
@@ -65,10 +65,11 @@ export class PDFiumPage {
|
|
|
65
65
|
/** Returns the page object at the given index with type and bounds. */
|
|
66
66
|
async getObject(index: number): Promise<PageObject> {
|
|
67
67
|
const obj = await withConcurrency(() => this.native.getObject(index));
|
|
68
|
-
// wrap the native render function on image objects with the concurrency
|
|
68
|
+
// wrap the native render function on image objects with the concurrency
|
|
69
|
+
// semaphore. `obj` is already narrowed to ImagePageObject by the guard.
|
|
69
70
|
if (obj.type === 'image') {
|
|
70
|
-
const nativeRender =
|
|
71
|
-
|
|
71
|
+
const nativeRender = obj.render.bind(obj);
|
|
72
|
+
obj.render = ((opts?: ImageRenderOptions) =>
|
|
72
73
|
withConcurrency(() => nativeRender(opts))) as ImagePageObject['render'];
|
|
73
74
|
}
|
|
74
75
|
return obj;
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdfium-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Native Node.js bindings for PDFium",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
|
+
"packageManager": "npm@11.17.0",
|
|
7
8
|
"engines": {
|
|
8
|
-
"node": ">=
|
|
9
|
+
"node": ">=22.0.0"
|
|
9
10
|
},
|
|
10
11
|
"keywords": [
|
|
11
12
|
"pdf",
|
|
@@ -32,7 +33,8 @@
|
|
|
32
33
|
".": {
|
|
33
34
|
"types": "./dist/index.d.ts",
|
|
34
35
|
"default": "./dist/index.js"
|
|
35
|
-
}
|
|
36
|
+
},
|
|
37
|
+
"./package.json": "./package.json"
|
|
36
38
|
},
|
|
37
39
|
"files": [
|
|
38
40
|
"dist",
|
|
@@ -42,7 +44,8 @@
|
|
|
42
44
|
"binding.gyp",
|
|
43
45
|
"README.md",
|
|
44
46
|
"CHANGELOG.md",
|
|
45
|
-
"LICENSE"
|
|
47
|
+
"LICENSE",
|
|
48
|
+
"THIRD-PARTY-NOTICES.md"
|
|
46
49
|
],
|
|
47
50
|
"repository": {
|
|
48
51
|
"type": "git",
|
|
@@ -72,7 +75,10 @@
|
|
|
72
75
|
"build:ts": "tsc",
|
|
73
76
|
"prepublishOnly": "tsc",
|
|
74
77
|
"download": "node scripts/download-pdfium.mjs",
|
|
78
|
+
"verify:checksums": "node scripts/verify-checksums.mjs",
|
|
75
79
|
"test": "vitest run",
|
|
80
|
+
"test:coverage": "vitest run --coverage",
|
|
81
|
+
"typecheck": "tsc --noEmit",
|
|
76
82
|
"lint": "eslint --fix .",
|
|
77
83
|
"lint:check": "eslint .",
|
|
78
84
|
"format": "prettier --write .",
|
|
@@ -80,8 +86,8 @@
|
|
|
80
86
|
"prepare": "husky && tsc"
|
|
81
87
|
},
|
|
82
88
|
"lint-staged": {
|
|
83
|
-
"*.{ts,js,json,md,yaml,yml}": "prettier --write",
|
|
84
|
-
"*.{ts,js}": "eslint --max-warnings 0"
|
|
89
|
+
"*.{ts,js,mjs,cjs,json,md,yaml,yml}": "prettier --write",
|
|
90
|
+
"*.{ts,js,mjs,cjs}": "eslint --max-warnings 0"
|
|
85
91
|
},
|
|
86
92
|
"dependencies": {
|
|
87
93
|
"node-addon-api": "^8.0.0",
|
|
@@ -89,15 +95,16 @@
|
|
|
89
95
|
},
|
|
90
96
|
"devDependencies": {
|
|
91
97
|
"@eslint/js": "^10.0.1",
|
|
92
|
-
"@types/node": "^
|
|
98
|
+
"@types/node": "^22.0.0",
|
|
99
|
+
"@vitest/coverage-v8": "^4.1.2",
|
|
93
100
|
"eslint": "^10.1.0",
|
|
94
101
|
"eslint-config-prettier": "^10.1.8",
|
|
95
|
-
"
|
|
102
|
+
"globals": "^17.0.0",
|
|
96
103
|
"husky": "^9.1.7",
|
|
97
|
-
"lint-staged": "^
|
|
104
|
+
"lint-staged": "^17.0.8",
|
|
98
105
|
"node-gyp": "^13.0.0",
|
|
99
106
|
"prettier": "^3.8.1",
|
|
100
|
-
"typescript": "^
|
|
107
|
+
"typescript": "^6.0.3",
|
|
101
108
|
"typescript-eslint": "^8.57.2",
|
|
102
109
|
"vitest": "^4.1.2"
|
|
103
110
|
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { execSync
|
|
2
|
-
import {
|
|
3
|
-
import { pipeline } from 'node:stream/promises';
|
|
4
|
-
import { Readable } from 'node:stream';
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, mkdirSync, rmSync } from 'node:fs';
|
|
5
3
|
import { join } from 'node:path';
|
|
4
|
+
import { downloadFile, extractTarball, loadManifest } from './lib/integrity.mjs';
|
|
6
5
|
|
|
7
|
-
const
|
|
8
|
-
const BASE_URL = 'https://github.com/bblanchon/pdfium-binaries/releases/download';
|
|
6
|
+
const { pdfium } = loadManifest();
|
|
9
7
|
|
|
10
8
|
// detect musl libc (Alpine, Void, etc.)
|
|
11
9
|
function isMusl() {
|
|
@@ -22,33 +20,16 @@ function isMusl() {
|
|
|
22
20
|
}
|
|
23
21
|
}
|
|
24
22
|
|
|
25
|
-
const TARGETS = {
|
|
26
|
-
// macOS
|
|
27
|
-
'darwin-arm64': 'pdfium-mac-arm64',
|
|
28
|
-
'darwin-x64': 'pdfium-mac-x64',
|
|
29
|
-
// Linux (glibc)
|
|
30
|
-
'linux-x64': 'pdfium-linux-x64',
|
|
31
|
-
'linux-arm64': 'pdfium-linux-arm64',
|
|
32
|
-
'linux-arm': 'pdfium-linux-arm',
|
|
33
|
-
'linux-ppc64': 'pdfium-linux-ppc64',
|
|
34
|
-
// Linux (musl / Alpine)
|
|
35
|
-
'linux-musl-x64': 'pdfium-linux-musl-x64',
|
|
36
|
-
'linux-musl-arm64': 'pdfium-linux-musl-arm64',
|
|
37
|
-
// Windows
|
|
38
|
-
'win32-x64': 'pdfium-win-x64',
|
|
39
|
-
'win32-arm64': 'pdfium-win-arm64',
|
|
40
|
-
};
|
|
41
|
-
|
|
42
23
|
const platform = process.platform;
|
|
43
24
|
// support cross-compilation via npm_config_arch (e.g. win32 x64 → arm64)
|
|
44
25
|
const arch = process.env.npm_config_arch || process.arch;
|
|
45
26
|
const musl = isMusl();
|
|
46
27
|
const key = musl ? `${platform}-musl-${arch}` : `${platform}-${arch}`;
|
|
47
|
-
const
|
|
28
|
+
const entry = pdfium.targets[key];
|
|
48
29
|
|
|
49
|
-
if (!
|
|
30
|
+
if (!entry) {
|
|
50
31
|
console.error(`Unsupported platform: ${key}`);
|
|
51
|
-
console.error(`Supported: ${Object.keys(
|
|
32
|
+
console.error(`Supported: ${Object.keys(pdfium.targets).join(', ')}`);
|
|
52
33
|
process.exit(1);
|
|
53
34
|
}
|
|
54
35
|
|
|
@@ -59,27 +40,22 @@ if (existsSync(join(depsDir, 'include', 'fpdfview.h'))) {
|
|
|
59
40
|
process.exit(0);
|
|
60
41
|
}
|
|
61
42
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const
|
|
43
|
+
// version is repo-controlled (native-deps.json); encode it so it can't escape
|
|
44
|
+
// the release path, and downloadFile pins both the origin and the SHA-256.
|
|
45
|
+
const url = `${pdfium.baseUrl}/${encodeURIComponent(pdfium.version)}/${entry.asset}`;
|
|
46
|
+
const tarball = join(import.meta.dirname, '..', entry.asset);
|
|
65
47
|
|
|
66
|
-
console.log(`Downloading PDFium ${
|
|
48
|
+
console.log(`Downloading PDFium ${pdfium.version} for ${key}...`);
|
|
67
49
|
console.log(`URL: ${url}`);
|
|
68
50
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
51
|
+
await downloadFile(url, tarball, {
|
|
52
|
+
expectedSha256: entry.sha256,
|
|
53
|
+
allowedOrigin: pdfium.origin,
|
|
54
|
+
});
|
|
74
55
|
|
|
75
|
-
|
|
76
|
-
await pipeline(Readable.fromWeb(response.body), createWriteStream(tarball));
|
|
77
|
-
|
|
78
|
-
console.log('Extracting...');
|
|
56
|
+
console.log('Checksum verified. Extracting...');
|
|
79
57
|
mkdirSync(depsDir, { recursive: true });
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
// clean up tarball
|
|
83
|
-
rmSync(tarball);
|
|
58
|
+
extractTarball(tarball, depsDir);
|
|
59
|
+
rmSync(tarball, { force: true });
|
|
84
60
|
|
|
85
61
|
console.log(`PDFium installed to ${depsDir}`);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate `scripts/prebuilds.json`: a map of "<platform>-<arch>" -> SHA-256 of
|
|
3
|
+
* each prebuilt release tarball.
|
|
4
|
+
*
|
|
5
|
+
* Run in the release workflow AFTER the prebuild artifacts are downloaded and
|
|
6
|
+
* BEFORE `npm publish`, so the pins ship *inside* the published (SLSA-attested)
|
|
7
|
+
* npm package. `install.mjs` then verifies a downloaded prebuilt against the
|
|
8
|
+
* pin baked into the package, closing the prebuilt-binary trust gap: a swapped
|
|
9
|
+
* GitHub release asset will not match the pin and falls back to the
|
|
10
|
+
* checksum-pinned source build.
|
|
11
|
+
*
|
|
12
|
+
* Usage: node scripts/gen-prebuild-manifest.mjs <artifacts-dir>
|
|
13
|
+
*/
|
|
14
|
+
import { readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
15
|
+
import { join } from 'node:path';
|
|
16
|
+
import { pathToFileURL } from 'node:url';
|
|
17
|
+
import { sha256File } from './lib/integrity.mjs';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Map every "<prefix>-v<version>-<platform>-<arch>.tar.gz" in `artifactsDir` to
|
|
21
|
+
* its SHA-256, keyed by "<platform>-<arch>" (matching install.mjs's lookup).
|
|
22
|
+
*
|
|
23
|
+
* @param {string} artifactsDir
|
|
24
|
+
* @param {string} version
|
|
25
|
+
* @returns {Promise<Record<string, string>>}
|
|
26
|
+
*/
|
|
27
|
+
export async function computePins(artifactsDir, version) {
|
|
28
|
+
// strip the "<prefix>-v<version>-" head and ".tar.gz" tail to recover the key
|
|
29
|
+
const headRe = new RegExp('^.*-v' + version.replace(/[.]/g, '\\.') + '-');
|
|
30
|
+
const files = readdirSync(artifactsDir)
|
|
31
|
+
.filter((f) => f.endsWith('.tar.gz'))
|
|
32
|
+
.sort();
|
|
33
|
+
const pins = {};
|
|
34
|
+
for (const file of files) {
|
|
35
|
+
const key = file.replace(/\.tar\.gz$/, '').replace(headRe, '');
|
|
36
|
+
pins[key] = await sha256File(join(artifactsDir, file));
|
|
37
|
+
}
|
|
38
|
+
return pins;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// CLI entrypoint (skipped when this module is imported, e.g. by tests)
|
|
42
|
+
if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
|
|
43
|
+
const artifactsDir = process.argv[2];
|
|
44
|
+
if (!artifactsDir) {
|
|
45
|
+
console.error('usage: node scripts/gen-prebuild-manifest.mjs <artifacts-dir>');
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
const root = join(import.meta.dirname, '..');
|
|
49
|
+
const { version } = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));
|
|
50
|
+
const pins = await computePins(artifactsDir, version);
|
|
51
|
+
if (Object.keys(pins).length === 0) {
|
|
52
|
+
console.error(`No .tar.gz artifacts found in ${artifactsDir}`);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
for (const [key, sha] of Object.entries(pins)) console.log(` ${key} ${sha}`);
|
|
56
|
+
const out = join(root, 'scripts', 'prebuilds.json');
|
|
57
|
+
writeFileSync(out, JSON.stringify(pins, null, 2) + '\n');
|
|
58
|
+
console.log(`Wrote ${Object.keys(pins).length} prebuild pin(s) to ${out}`);
|
|
59
|
+
}
|
package/scripts/install.mjs
CHANGED
|
@@ -6,16 +6,30 @@
|
|
|
6
6
|
* Musl (Alpine) naming: pdfium-v{version}-linux-musl-{arch}.tar.gz
|
|
7
7
|
* Contents: build/Release/pdfium.node + build/Release/libpdfium.{dylib,so,dll}
|
|
8
8
|
*/
|
|
9
|
-
import {
|
|
9
|
+
import { execSync } from 'node:child_process';
|
|
10
10
|
import { createWriteStream, existsSync, mkdirSync, readFileSync, unlinkSync } from 'node:fs';
|
|
11
11
|
import { join } from 'node:path';
|
|
12
12
|
import { Readable } from 'node:stream';
|
|
13
13
|
import { pipeline } from 'node:stream/promises';
|
|
14
|
+
import { extractTarball, verifyPrebuild } from './lib/integrity.mjs';
|
|
14
15
|
|
|
15
16
|
const root = join(import.meta.dirname, '..');
|
|
16
17
|
const pkg = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));
|
|
17
18
|
const version = pkg.version;
|
|
18
19
|
|
|
20
|
+
// Per-platform SHA-256 pins for the prebuilt tarballs, generated at release
|
|
21
|
+
// time (scripts/gen-prebuild-manifest.mjs) and shipped inside this package.
|
|
22
|
+
// The prebuilt binary is the code that actually runs, so it is verified against
|
|
23
|
+
// this pin before use; a swapped release asset fails the check and we fall back
|
|
24
|
+
// to the checksum-pinned source build.
|
|
25
|
+
function loadPrebuildPins() {
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(readFileSync(join(import.meta.dirname, 'prebuilds.json'), 'utf8'));
|
|
28
|
+
} catch {
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
19
33
|
// validate version to prevent SSRF via malicious package.json
|
|
20
34
|
if (!/^\d+\.\d+\.\d+(-[a-zA-Z0-9.]+)?$/.test(version)) {
|
|
21
35
|
console.error(`Invalid version format: ${version}`);
|
|
@@ -57,7 +71,7 @@ async function tryDownload() {
|
|
|
57
71
|
if (releaseUrl.origin !== releaseOrigin) {
|
|
58
72
|
throw new Error(`Unexpected URL origin: ${releaseUrl.origin}`);
|
|
59
73
|
}
|
|
60
|
-
const res = await fetch(releaseUrl, { redirect: 'follow' });
|
|
74
|
+
const res = await fetch(releaseUrl, { redirect: 'follow', signal: AbortSignal.timeout(60000) });
|
|
61
75
|
if (!res.ok) {
|
|
62
76
|
console.log(`No prebuilt binary found (HTTP ${res.status}), will compile from source.`);
|
|
63
77
|
return false;
|
|
@@ -73,8 +87,25 @@ async function tryDownload() {
|
|
|
73
87
|
|
|
74
88
|
await pipeline(Readable.fromWeb(body), fileStream);
|
|
75
89
|
|
|
76
|
-
//
|
|
77
|
-
|
|
90
|
+
// verify the prebuilt against the pinned checksum before trusting it
|
|
91
|
+
const pinKey = `${platformKey}-${arch}`;
|
|
92
|
+
const check = await verifyPrebuild(tmpTar, pinKey, loadPrebuildPins());
|
|
93
|
+
if (!check.ok) {
|
|
94
|
+
if (check.reason === 'no-pin') {
|
|
95
|
+
console.log(
|
|
96
|
+
`No pinned checksum for ${pinKey}; refusing unverified prebuilt, will compile from source.`,
|
|
97
|
+
);
|
|
98
|
+
} else {
|
|
99
|
+
console.log(
|
|
100
|
+
`Prebuilt checksum mismatch for ${pinKey} (expected ${check.expected}, got ${check.actual}); will compile from source.`,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
unlinkSync(tmpTar);
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// extract tar.gz into project root (hardened: no -P, no archived ownership)
|
|
108
|
+
extractTarball(tmpTar, root);
|
|
78
109
|
unlinkSync(tmpTar);
|
|
79
110
|
|
|
80
111
|
// verify the .node file exists
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared download/verify helpers for the install and dependency-build scripts.
|
|
3
|
+
*
|
|
4
|
+
* Goals:
|
|
5
|
+
* - never trust the network blindly: verify a pinned SHA-256 before use,
|
|
6
|
+
* - survive flaky connections: timeout + exponential-backoff retry,
|
|
7
|
+
* - never leave a half-written file behind: download to `<dest>.part` and
|
|
8
|
+
* rename atomically only after the checksum passes,
|
|
9
|
+
* - extract archives without restoring archived ownership or honouring
|
|
10
|
+
* absolute/`..` paths (tar's default, kept by NOT passing -P).
|
|
11
|
+
*/
|
|
12
|
+
import { execFileSync } from 'node:child_process';
|
|
13
|
+
import { createHash } from 'node:crypto';
|
|
14
|
+
import {
|
|
15
|
+
createReadStream,
|
|
16
|
+
createWriteStream,
|
|
17
|
+
mkdirSync,
|
|
18
|
+
readFileSync,
|
|
19
|
+
rmSync,
|
|
20
|
+
renameSync,
|
|
21
|
+
} from 'node:fs';
|
|
22
|
+
import { dirname, join } from 'node:path';
|
|
23
|
+
import { Readable } from 'node:stream';
|
|
24
|
+
import { pipeline } from 'node:stream/promises';
|
|
25
|
+
|
|
26
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
27
|
+
|
|
28
|
+
/** Compute the SHA-256 of a file as a lowercase hex string. */
|
|
29
|
+
export async function sha256File(path) {
|
|
30
|
+
const hash = createHash('sha256');
|
|
31
|
+
await pipeline(createReadStream(path), hash);
|
|
32
|
+
return hash.digest('hex');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Decide whether a downloaded prebuilt tarball is trusted by comparing its
|
|
37
|
+
* SHA-256 to the pin recorded for `pinKey` in `pins` (scripts/prebuilds.json).
|
|
38
|
+
* Returns a discriminated result so the installer can log and fall back to a
|
|
39
|
+
* source build instead of running an unverified binary.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} tarPath
|
|
42
|
+
* @param {string} pinKey e.g. "darwin-arm64" / "linux-musl-x64"
|
|
43
|
+
* @param {Record<string, string>} pins
|
|
44
|
+
* @returns {Promise<{ok: true, pinKey: string, sha256: string}
|
|
45
|
+
* | {ok: false, reason: 'no-pin', pinKey: string}
|
|
46
|
+
* | {ok: false, reason: 'mismatch', pinKey: string, expected: string, actual: string}>}
|
|
47
|
+
*/
|
|
48
|
+
export async function verifyPrebuild(tarPath, pinKey, pins) {
|
|
49
|
+
const expected = pins[pinKey];
|
|
50
|
+
if (!expected) return { ok: false, reason: 'no-pin', pinKey };
|
|
51
|
+
const actual = await sha256File(tarPath);
|
|
52
|
+
if (actual !== expected.toLowerCase()) {
|
|
53
|
+
return { ok: false, reason: 'mismatch', pinKey, expected, actual };
|
|
54
|
+
}
|
|
55
|
+
return { ok: true, pinKey, sha256: actual };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Read the native-dependency manifest (scripts/native-deps.json). */
|
|
59
|
+
export function loadManifest() {
|
|
60
|
+
return JSON.parse(readFileSync(join(import.meta.dirname, '..', 'native-deps.json'), 'utf8'));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Download `url` to `dest` with a per-attempt timeout and exponential-backoff
|
|
65
|
+
* retry. Writes to `<dest>.part` (same filesystem, so the rename is atomic) and
|
|
66
|
+
* only promotes it once the optional `expectedSha256` matches. A checksum
|
|
67
|
+
* mismatch or unexpected origin fails immediately (not retried).
|
|
68
|
+
*
|
|
69
|
+
* @param {string} url
|
|
70
|
+
* @param {string} dest
|
|
71
|
+
* @param {{ expectedSha256?: string, allowedOrigin?: string, timeoutMs?: number, retries?: number }} [opts]
|
|
72
|
+
*/
|
|
73
|
+
export async function downloadFile(url, dest, opts = {}) {
|
|
74
|
+
const { expectedSha256, allowedOrigin, timeoutMs = 60000, retries = 4 } = opts;
|
|
75
|
+
|
|
76
|
+
const u = new URL(url);
|
|
77
|
+
if (allowedOrigin && u.origin !== allowedOrigin) {
|
|
78
|
+
throw new Error(`Refusing to download from unexpected origin: ${u.origin}`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
mkdirSync(dirname(dest), { recursive: true });
|
|
82
|
+
const tmp = `${dest}.part`;
|
|
83
|
+
|
|
84
|
+
let lastErr;
|
|
85
|
+
for (let attempt = 1; attempt <= retries; attempt++) {
|
|
86
|
+
try {
|
|
87
|
+
const res = await fetch(u, { redirect: 'follow', signal: AbortSignal.timeout(timeoutMs) });
|
|
88
|
+
if (!res.ok) throw new Error(`HTTP ${res.status} ${res.statusText}`);
|
|
89
|
+
if (!res.body) throw new Error('empty response body');
|
|
90
|
+
await pipeline(Readable.fromWeb(res.body), createWriteStream(tmp));
|
|
91
|
+
|
|
92
|
+
if (expectedSha256) {
|
|
93
|
+
const actual = await sha256File(tmp);
|
|
94
|
+
if (actual !== expectedSha256.toLowerCase()) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
`checksum mismatch for ${u.href}\n expected ${expectedSha256}\n actual ${actual}`,
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
renameSync(tmp, dest);
|
|
102
|
+
return dest;
|
|
103
|
+
} catch (err) {
|
|
104
|
+
lastErr = err;
|
|
105
|
+
rmSync(tmp, { force: true });
|
|
106
|
+
const msg = String(err?.message ?? err);
|
|
107
|
+
// integrity failures are not transient — surface them immediately
|
|
108
|
+
if (msg.includes('checksum mismatch') || msg.includes('unexpected origin')) throw err;
|
|
109
|
+
if (attempt < retries) {
|
|
110
|
+
const backoff = Math.min(1000 * 2 ** (attempt - 1), 8000);
|
|
111
|
+
console.warn(` attempt ${attempt}/${retries} failed (${msg}); retrying in ${backoff}ms`);
|
|
112
|
+
await sleep(backoff);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
throw new Error(`Failed to download ${u.href} after ${retries} attempts: ${lastErr?.message}`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Extract a .tar.gz / .tar.xz into `destDir`. Compression is auto-detected.
|
|
121
|
+
* Not passing `-P` keeps tar's default refusal of absolute and `..` paths;
|
|
122
|
+
* `--no-same-owner` avoids restoring archived uid/gid.
|
|
123
|
+
*/
|
|
124
|
+
export function extractTarball(tarball, destDir, { strip } = {}) {
|
|
125
|
+
mkdirSync(destDir, { recursive: true });
|
|
126
|
+
const args = ['-xf', tarball, '-C', destDir, '--no-same-owner'];
|
|
127
|
+
if (strip) args.push('--strip-components', String(strip));
|
|
128
|
+
execFileSync('tar', args, { stdio: 'inherit' });
|
|
129
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"pdfium": {
|
|
3
|
+
"version": "chromium/7920",
|
|
4
|
+
"origin": "https://github.com",
|
|
5
|
+
"baseUrl": "https://github.com/bblanchon/pdfium-binaries/releases/download",
|
|
6
|
+
"checksumSource": "Sigstore SLSA provenance attestation (pdfium-attestation.json) attached to the bblanchon/pdfium-binaries release",
|
|
7
|
+
"targets": {
|
|
8
|
+
"darwin-arm64": {
|
|
9
|
+
"asset": "pdfium-mac-arm64.tgz",
|
|
10
|
+
"sha256": "c032aa59be58b0f12e41e76a8ef707e347b9841b0426446f646b2568d350ec4f"
|
|
11
|
+
},
|
|
12
|
+
"darwin-x64": {
|
|
13
|
+
"asset": "pdfium-mac-x64.tgz",
|
|
14
|
+
"sha256": "0c78b8d55a4c97e02c9bb516997253cb972739373009cf29554c959a2f6b194a"
|
|
15
|
+
},
|
|
16
|
+
"linux-x64": {
|
|
17
|
+
"asset": "pdfium-linux-x64.tgz",
|
|
18
|
+
"sha256": "49ab3afbd4e6c1e284b5f2898129c8bb8a10fd785c1c5392c8c1fc70242f9ced"
|
|
19
|
+
},
|
|
20
|
+
"linux-arm64": {
|
|
21
|
+
"asset": "pdfium-linux-arm64.tgz",
|
|
22
|
+
"sha256": "00551476a77fbc1a31c37573eadc9b63f1c366f65ad727539326927da083bb4d"
|
|
23
|
+
},
|
|
24
|
+
"linux-arm": {
|
|
25
|
+
"asset": "pdfium-linux-arm.tgz",
|
|
26
|
+
"sha256": "b430bb61d27fee059a80f3219921daf30ac021acda2696f41e0d15b236d38569"
|
|
27
|
+
},
|
|
28
|
+
"linux-ppc64": {
|
|
29
|
+
"asset": "pdfium-linux-ppc64.tgz",
|
|
30
|
+
"sha256": "56bb7196e36b219c2a5ebc54c7f140a84b10458911fe16cee2b88e50644684d3"
|
|
31
|
+
},
|
|
32
|
+
"linux-musl-x64": {
|
|
33
|
+
"asset": "pdfium-linux-musl-x64.tgz",
|
|
34
|
+
"sha256": "4471ccd9d4f64ff16ac592d97016e404ec888d1c17fc1b3d0cd6e4763b47275c"
|
|
35
|
+
},
|
|
36
|
+
"linux-musl-arm64": {
|
|
37
|
+
"asset": "pdfium-linux-musl-arm64.tgz",
|
|
38
|
+
"sha256": "62e75cd629dc6a810d4f72ea864d2ba2f41b7e2141920161868869c8cc2c5912"
|
|
39
|
+
},
|
|
40
|
+
"win32-x64": {
|
|
41
|
+
"asset": "pdfium-win-x64.tgz",
|
|
42
|
+
"sha256": "bf25149815b34b00042f48a886653d469c817529dd9cccabb4b509b6465a9526"
|
|
43
|
+
},
|
|
44
|
+
"win32-arm64": {
|
|
45
|
+
"asset": "pdfium-win-arm64.tgz",
|
|
46
|
+
"sha256": "7d580ba612765063f9bb76b5c6571db5144714a4dc9cd6d448763d788de8f9fb"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"darwin-arm64": "2ed3388d9f273684c63533d000d2abaac3681a72e2319e6bcde47b225ff9e463",
|
|
3
|
+
"darwin-x64": "ce3333a27561877c1c0813d2c7c9ffcfc46da0a96eb51e78da79c7ff1e7bbda6",
|
|
4
|
+
"linux-arm": "66b372a255aaf5ed9a59b932e5172dfb2d423ec3d863d8eba90b8409d6611cd7",
|
|
5
|
+
"linux-arm64": "c703c8565bd9bd408c09a3ebff244abddb968e3c975a09cc1f176d5e3e326b8f",
|
|
6
|
+
"linux-musl-arm64": "16aaacba6068fa870791accd2de9292cd61ed17a04e67e508a140ed58c9f6e25",
|
|
7
|
+
"linux-musl-x64": "6116655f71164974eaa794189ff19afd87d2c5c95909874cb06734d36301f39a",
|
|
8
|
+
"linux-ppc64": "c0d2ab7094468f011713ec5b9880f5a074c97cbff4cc2f111aca6d8655c3bcc1",
|
|
9
|
+
"linux-x64": "6aa0fd743f4ad507ccc666fe9f7ebbf14448265fde1026eac1c70be448edfe9a",
|
|
10
|
+
"win32-arm64": "1b6bb07c471072e35ea8737f9c29a2d5e641dda7f8220f501afccceb53d1c8df",
|
|
11
|
+
"win32-x64": "9719f7ad5d00b5cf660e27e47844a7a44fb2f929d4b280f88be281ad4708d167"
|
|
12
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check each native dependency in native-deps.json for a newer upstream GitHub
|
|
3
|
+
* release and, when found, re-pin the version and re-hash the asset(s).
|
|
4
|
+
*
|
|
5
|
+
* This is the piece Dependabot cannot do: the prebuilt/source native libraries
|
|
6
|
+
* are upstream release tarballs, not a package-manager ecosystem. Runs in CI
|
|
7
|
+
* (see .github/workflows/update-native-deps.yml) and emits a markdown summary
|
|
8
|
+
* for the pull-request body via GITHUB_OUTPUT.
|
|
9
|
+
*
|
|
10
|
+
* Supports both manifest shapes:
|
|
11
|
+
* - per-platform "targets" (baseUrl + { asset, sha256 } map), version == full tag
|
|
12
|
+
* - single "url" + "sha256", version == numeric (tag with any v/n prefix stripped)
|
|
13
|
+
*
|
|
14
|
+
* Only upstreams that publish a GitHub Release are tracked; a dependency whose
|
|
15
|
+
* repo has no usable release is skipped with a warning (kept manual) rather than
|
|
16
|
+
* guessed from noisy git tags.
|
|
17
|
+
*/
|
|
18
|
+
import { createHash } from 'node:crypto';
|
|
19
|
+
import { appendFileSync, readFileSync, writeFileSync } from 'node:fs';
|
|
20
|
+
import { join } from 'node:path';
|
|
21
|
+
import { Readable } from 'node:stream';
|
|
22
|
+
import { pipeline } from 'node:stream/promises';
|
|
23
|
+
|
|
24
|
+
const manifestPath = join(import.meta.dirname, 'native-deps.json');
|
|
25
|
+
const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
26
|
+
|
|
27
|
+
const token = process.env.GITHUB_TOKEN;
|
|
28
|
+
const apiHeaders = {
|
|
29
|
+
accept: 'application/vnd.github+json',
|
|
30
|
+
'user-agent': 'update-native-deps',
|
|
31
|
+
...(token ? { authorization: `Bearer ${token}` } : {}),
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// derive "OWNER/REPO" from a github.com baseUrl (targets shape) or url (single)
|
|
35
|
+
function repoFor(dep) {
|
|
36
|
+
const source = dep.baseUrl ?? dep.url;
|
|
37
|
+
const match = /^https:\/\/github\.com\/([^/]+\/[^/]+)/.exec(source ?? '');
|
|
38
|
+
if (!match) throw new Error(`cannot derive a github.com OWNER/REPO from: ${source}`);
|
|
39
|
+
return match[1];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// returns the latest release tag, or null when the repo publishes no release
|
|
43
|
+
async function latestReleaseTag(repo) {
|
|
44
|
+
const res = await fetch(`https://api.github.com/repos/${repo}/releases/latest`, {
|
|
45
|
+
headers: apiHeaders,
|
|
46
|
+
signal: AbortSignal.timeout(30000),
|
|
47
|
+
});
|
|
48
|
+
if (res.status === 404) return null;
|
|
49
|
+
if (!res.ok) throw new Error(`GitHub API returned HTTP ${res.status} for ${repo} latest release`);
|
|
50
|
+
const { tag_name: tag } = await res.json();
|
|
51
|
+
if (!tag) throw new Error(`latest release for ${repo} has no tag_name`);
|
|
52
|
+
return tag;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function sha256Url(url, allowedOrigin) {
|
|
56
|
+
const parsed = new URL(url);
|
|
57
|
+
if (allowedOrigin && parsed.origin !== allowedOrigin) {
|
|
58
|
+
throw new Error(`refusing to fetch from unexpected origin: ${parsed.origin}`);
|
|
59
|
+
}
|
|
60
|
+
const res = await fetch(parsed, { redirect: 'follow', signal: AbortSignal.timeout(120000) });
|
|
61
|
+
if (!res.ok) throw new Error(`HTTP ${res.status} for ${parsed.href}`);
|
|
62
|
+
if (!res.body) throw new Error(`empty response body for ${parsed.href}`);
|
|
63
|
+
const hash = createHash('sha256');
|
|
64
|
+
await pipeline(Readable.fromWeb(res.body), hash);
|
|
65
|
+
return hash.digest('hex');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const changes = [];
|
|
69
|
+
for (const [name, dep] of Object.entries(manifest)) {
|
|
70
|
+
const repo = repoFor(dep);
|
|
71
|
+
const tag = await latestReleaseTag(repo);
|
|
72
|
+
if (tag === null) {
|
|
73
|
+
console.warn(`${name}: ${repo} publishes no GitHub release; skipping (update manually)`);
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (dep.targets) {
|
|
78
|
+
// targets shape: version is the full tag (e.g. "chromium/7920")
|
|
79
|
+
if (tag === dep.version) {
|
|
80
|
+
console.log(`${name}: up to date (${dep.version})`);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
console.log(
|
|
84
|
+
`${name}: ${dep.version} -> ${tag}; re-hashing ${Object.keys(dep.targets).length} targets`,
|
|
85
|
+
);
|
|
86
|
+
for (const [key, target] of Object.entries(dep.targets)) {
|
|
87
|
+
const url = `${dep.baseUrl}/${encodeURIComponent(tag)}/${target.asset}`;
|
|
88
|
+
target.sha256 = await sha256Url(url, dep.origin);
|
|
89
|
+
console.log(` ${key}: ${target.sha256}`);
|
|
90
|
+
}
|
|
91
|
+
changes.push({ name, from: dep.version, to: tag });
|
|
92
|
+
dep.version = tag;
|
|
93
|
+
} else {
|
|
94
|
+
// single-url shape: manifest version is numeric; the tag may carry a v/n
|
|
95
|
+
// prefix. The url embeds the version string, so a plain substitution rebuilds
|
|
96
|
+
// both the tag segment and the filename.
|
|
97
|
+
const version = tag.replace(/^[^0-9]*/, '');
|
|
98
|
+
if (version === dep.version) {
|
|
99
|
+
console.log(`${name}: up to date (${dep.version})`);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const url = dep.url.replaceAll(dep.version, version);
|
|
103
|
+
console.log(`${name}: ${dep.version} -> ${version}; re-hashing`);
|
|
104
|
+
dep.sha256 = await sha256Url(url, dep.origin);
|
|
105
|
+
dep.url = url;
|
|
106
|
+
changes.push({ name, from: dep.version, to: version });
|
|
107
|
+
dep.version = version;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (changes.length === 0) {
|
|
112
|
+
console.log('\nAll native dependencies are up to date.');
|
|
113
|
+
} else {
|
|
114
|
+
writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
|
|
115
|
+
const summary = changes.map((c) => `- **${c.name}**: \`${c.from}\` → \`${c.to}\``).join('\n');
|
|
116
|
+
console.log(`\n${summary}`);
|
|
117
|
+
|
|
118
|
+
if (process.env.GITHUB_OUTPUT) {
|
|
119
|
+
const body = [
|
|
120
|
+
'Automated native dependency update.',
|
|
121
|
+
'',
|
|
122
|
+
summary,
|
|
123
|
+
'',
|
|
124
|
+
'Checksums were recomputed from the upstream release assets. `verify-checksums` re-downloads each asset and confirms it matches the recorded hash — a consistency check against the same source, not independent provenance.',
|
|
125
|
+
].join('\n');
|
|
126
|
+
appendFileSync(process.env.GITHUB_OUTPUT, 'changed=true\n');
|
|
127
|
+
appendFileSync(process.env.GITHUB_OUTPUT, `body<<PR_BODY_EOF\n${body}\nPR_BODY_EOF\n`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verify that the SHA-256 hashes pinned in native-deps.json still match what
|
|
3
|
+
* the upstream URLs serve. Use after a version bump, or in CI as a supply-chain
|
|
4
|
+
* tripwire. By default only this platform's artifacts are checked; pass --all
|
|
5
|
+
* to verify every pinned target (large download for prebuilt-binary deps).
|
|
6
|
+
*/
|
|
7
|
+
import { rmSync } from 'node:fs';
|
|
8
|
+
import { tmpdir } from 'node:os';
|
|
9
|
+
import { join } from 'node:path';
|
|
10
|
+
import { downloadFile, loadManifest } from './lib/integrity.mjs';
|
|
11
|
+
|
|
12
|
+
const all = process.argv.includes('--all');
|
|
13
|
+
const manifest = loadManifest();
|
|
14
|
+
const platform = process.platform;
|
|
15
|
+
const arch = process.arch;
|
|
16
|
+
|
|
17
|
+
const checks = [];
|
|
18
|
+
for (const [name, dep] of Object.entries(manifest)) {
|
|
19
|
+
if (dep.targets) {
|
|
20
|
+
for (const [key, t] of Object.entries(dep.targets)) {
|
|
21
|
+
if (!all && key !== `${platform}-${arch}` && key !== `${platform}-musl-${arch}`) continue;
|
|
22
|
+
checks.push({
|
|
23
|
+
label: `${name} ${key}`,
|
|
24
|
+
url: `${dep.baseUrl}/${encodeURIComponent(dep.version)}/${t.asset}`,
|
|
25
|
+
sha256: t.sha256,
|
|
26
|
+
origin: dep.origin,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
} else {
|
|
30
|
+
checks.push({
|
|
31
|
+
label: `${name} ${dep.version}`,
|
|
32
|
+
url: dep.url,
|
|
33
|
+
sha256: dep.sha256,
|
|
34
|
+
origin: dep.origin,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let failed = 0;
|
|
40
|
+
for (const c of checks) {
|
|
41
|
+
const tmp = join(tmpdir(), `verify-${c.label.replace(/\W+/g, '-')}`);
|
|
42
|
+
try {
|
|
43
|
+
process.stdout.write(`Verifying ${c.label} ... `);
|
|
44
|
+
await downloadFile(c.url, tmp, { expectedSha256: c.sha256, allowedOrigin: c.origin });
|
|
45
|
+
console.log('OK');
|
|
46
|
+
} catch (err) {
|
|
47
|
+
console.log(`FAIL\n ${err.message}`);
|
|
48
|
+
failed++;
|
|
49
|
+
} finally {
|
|
50
|
+
rmSync(tmp, { force: true });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (failed) {
|
|
55
|
+
console.error(`\n${failed} checksum(s) did not match.`);
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
console.log(`\nAll ${checks.length} checksum(s) verified.`);
|