dsh-image-integrity 0.0.0-stage → 0.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/CHANGELOG.md +54 -0
- package/LICENSE +201 -0
- package/README-zh.md +98 -0
- package/README.md +100 -2
- package/cordis.patch.yml +20 -0
- package/lib/analyze.d.ts +108 -0
- package/lib/analyze.d.ts.map +1 -0
- package/lib/analyze.js +310 -0
- package/lib/analyze.js.map +1 -0
- package/lib/config.d.ts +40 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +61 -0
- package/lib/config.js.map +1 -0
- package/lib/index.d.ts +37 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +50 -0
- package/lib/index.js.map +1 -0
- package/lib/png.d.ts +48 -0
- package/lib/png.d.ts.map +1 -0
- package/lib/png.js +232 -0
- package/lib/png.js.map +1 -0
- package/lib/report.d.ts +15 -0
- package/lib/report.d.ts.map +1 -0
- package/lib/report.js +62 -0
- package/lib/report.js.map +1 -0
- package/lib/runtime.d.ts +89 -0
- package/lib/runtime.d.ts.map +1 -0
- package/lib/runtime.js +199 -0
- package/lib/runtime.js.map +1 -0
- package/lib/tools/image-check.d.ts +12 -0
- package/lib/tools/image-check.d.ts.map +1 -0
- package/lib/tools/image-check.js +79 -0
- package/lib/tools/image-check.js.map +1 -0
- package/lib/tools/image-compare.d.ts +12 -0
- package/lib/tools/image-compare.d.ts.map +1 -0
- package/lib/tools/image-compare.js +79 -0
- package/lib/tools/image-compare.js.map +1 -0
- package/lib/tools/image-report.d.ts +10 -0
- package/lib/tools/image-report.d.ts.map +1 -0
- package/lib/tools/image-report.js +88 -0
- package/lib/tools/image-report.js.map +1 -0
- package/lib/tools/shared.d.ts +20 -0
- package/lib/tools/shared.d.ts.map +1 -0
- package/lib/tools/shared.js +14 -0
- package/lib/tools/shared.js.map +1 -0
- package/lib/version.d.ts +7 -0
- package/lib/version.d.ts.map +1 -0
- package/lib/version.js +7 -0
- package/lib/version.js.map +1 -0
- package/package.json +79 -4
- package/src/analyze.ts +374 -0
- package/src/config.ts +87 -0
- package/src/index.ts +60 -0
- package/src/png.ts +253 -0
- package/src/report.ts +63 -0
- package/src/runtime.ts +245 -0
- package/src/tools/image-check.ts +78 -0
- package/src/tools/image-compare.ts +78 -0
- package/src/tools/image-report.ts +91 -0
- package/src/tools/shared.ts +14 -0
- package/src/version.ts +7 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
|
|
5
|
+
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- Enforce `maxPixels` from the IHDR **before** inflating IDAT, and pass the
|
|
12
|
+
expected decompressed size as `inflateSync.maxOutputLength`; a small PNG with
|
|
13
|
+
huge dimensions can no longer allocate an arbitrarily large buffer. The
|
|
14
|
+
exported decoder also defaults to the same 4,000,000-pixel cap.
|
|
15
|
+
- Validate per-call thresholds (`blockSize` 2–256, `maxShiftBits`
|
|
16
|
+
0–blockSize², finite non-negative `minVariance`, NCC 0–1) so `blockSize: 0`
|
|
17
|
+
cannot loop forever and NaN/out-of-range options cannot silently disable
|
|
18
|
+
detection.
|
|
19
|
+
- `image_report` validates the analysis/matches shapes and returns
|
|
20
|
+
`INVALID_INPUT` instead of dereferencing undefined fields.
|
|
21
|
+
- Report the effective block size in `blocks` when the image is smaller than
|
|
22
|
+
the requested block, matching `blockSize` and `considered`.
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
|
|
26
|
+
- Precompute mirrored bit patterns once per block and stop Hamming counting
|
|
27
|
+
once the tolerance is exceeded, removing per-pair mirror allocations from
|
|
28
|
+
the O(n²) comparison loop.
|
|
29
|
+
- Test count is now 22; README/CHANGELOG list the new failure branches.
|
|
30
|
+
|
|
31
|
+
## [0.1.0] - 2026-11-08
|
|
32
|
+
|
|
33
|
+
First release: block-level image reuse detection.
|
|
34
|
+
|
|
35
|
+
### Added
|
|
36
|
+
|
|
37
|
+
- `image_check`: duplicated and mirrored 16×16 textured blocks inside one PNG,
|
|
38
|
+
with Hamming/NCC scores.
|
|
39
|
+
- `image_compare`: shared duplicated/mirrored blocks between two PNGs; a
|
|
40
|
+
dimension mismatch is reported, never resized.
|
|
41
|
+
- `image_report`: Markdown + SARIF 2.1.0.
|
|
42
|
+
- Zero-dependency PNG decoder (8-bit, non-interlaced, grey/RGB/RGBA) with
|
|
43
|
+
bounds-checked chunks, plus a greyscale encoder used by tests.
|
|
44
|
+
- False-positive controls: flat blocks and blocks that are close to a fitted
|
|
45
|
+
plane are ignored, so smooth gradients do not read as duplicates.
|
|
46
|
+
- REP v1 integration: image bytes become immutable snapshots with figure
|
|
47
|
+
anchors (ordinal included), one check per matched region, and a valid record.
|
|
48
|
+
- 18 tests.
|
|
49
|
+
|
|
50
|
+
### Notes
|
|
51
|
+
|
|
52
|
+
- Finds reused pixels, not manipulation intent; repeated controls are normal.
|
|
53
|
+
- JPEG/WebP/TIFF are not decoded in v0.1 and are rejected explicitly.
|
|
54
|
+
- The 100-pair benchmark is not yet frozen; no benchmark numbers are claimed.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README-zh.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# dsh-image-integrity
|
|
2
|
+
|
|
3
|
+
**这张子图是不是被复用了 —— 原地重复,还是从另一张图镜像粘贴过来?**
|
|
4
|
+
|
|
5
|
+
*零依赖 PNG 解码、带 NCC 确认的均值阈值块指纹、重复/镜像区域报告、REP 证据与 SARIF。它找的是被复用的像素,而不是操纵意图。*
|
|
6
|
+
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
[]()
|
|
9
|
+
|
|
10
|
+
[English](README.md) · 简体中文
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## 它做什么
|
|
15
|
+
|
|
16
|
+
- **`image_check`** —— 在单张图片内找出出现两次(或以镜像形式出现)的纹理块。
|
|
17
|
+
- **`image_compare`** —— 找出两张图片之间共有的块,包括镜像副本。
|
|
18
|
+
- **`image_report`** —— Markdown + SARIF 2.1.0,每个匹配区域一条 warning,附坐标、汉明距离与 NCC。
|
|
19
|
+
|
|
20
|
+
工作原理:解码 PNG → 亮度 → 16×16 块 → 均值阈值位模式(可抵抗亮度偏移)+ 零均值 NCC 确认。平坦**或接近拟合平面**的块会被跳过,因此平滑渐变不会被报成“重复”。
|
|
21
|
+
|
|
22
|
+
## 它不做什么
|
|
23
|
+
|
|
24
|
+
- **不支持 JPEG。** 只解码 8 位非隔行 PNG(灰度/RGB/RGBA)。JPEG/16 位/隔行 PNG 会以明确的错误码拒绝 —— 不会静默返回垃圾结果。
|
|
25
|
+
- **不做对齐。** 图片尺寸必须完全相同;尺寸不一致会报告,绝不缩放。
|
|
26
|
+
- **不抗模糊/压缩。** 经 JPEG 重压缩、缩放、旋转或拼接混合后,通常就检测不出来了。
|
|
27
|
+
- **不指控学术不端。** 重复的对照图、比例尺、图标与背景纹理都是合法的共享块。报告会说明这一点。
|
|
28
|
+
- **没有 GUI,也不上传。** 只处理本地字节。
|
|
29
|
+
|
|
30
|
+
## 工具
|
|
31
|
+
|
|
32
|
+
### `image_check`
|
|
33
|
+
|
|
34
|
+
`{ path, persist?, blockSize?, maxShiftBits?, minVariance?, nccThreshold? }` → `{ ok, analysis, evidenceId?, recordPath? }`。
|
|
35
|
+
|
|
36
|
+
### `image_compare`
|
|
37
|
+
|
|
38
|
+
`{ pathA, pathB, persist?, ...thresholds }` → `{ ok, analysis, evidenceId?, recordPath? }`。
|
|
39
|
+
|
|
40
|
+
### `image_report`
|
|
41
|
+
|
|
42
|
+
`{ analysis, imageId? }` → `{ ok, markdown, sarif }`。
|
|
43
|
+
|
|
44
|
+
### 错误码
|
|
45
|
+
|
|
46
|
+
`INVALID_INPUT` · `NOT_FOUND` · `PATH_ESCAPE` · `NOT_A_FILE` · `TOO_LARGE` · `UNSUPPORTED_IMAGE` · `STORE_ERROR`
|
|
47
|
+
|
|
48
|
+
## 兼容性与安装
|
|
49
|
+
|
|
50
|
+
| | |
|
|
51
|
+
|---|---|
|
|
52
|
+
| DeepSeek Harness | **`dsh-v0.2.1-rc.5`**(2026-11-08 实测);peer `>=0.2.1-0 <0.3.0 \|\| >=0.2.2-0 <0.3.0` |
|
|
53
|
+
| Node | `^22.19.0 \|\| >=24.9.0`(实测 `24.22.1`),仅 ESM |
|
|
54
|
+
| Peer 依赖 | `@perrylink/dsh-research-core ^0.1.0`、`@deepseek-ai/cordis ^4.0.5-alpha.1`、`@deepseek-ai/dsh-tools`、`@deepseek-ai/schemastery ^3.18.5-alpha.1` |
|
|
55
|
+
| 运行时依赖 | **零**(PNG 解码通过 `node:zlib`) |
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
dsh plugin --profile <name> add @perrylink/dsh-research-core dsh-image-integrity
|
|
59
|
+
dsh --profile <name> --dump-config | grep dsh-image-integrity
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## 配置
|
|
63
|
+
|
|
64
|
+
| 键 | 默认值 | 含义 |
|
|
65
|
+
|---|---|---|
|
|
66
|
+
| `enabled` | `true` | `false` 时不挂载任何内容 |
|
|
67
|
+
| `root` | `.image-integrity` | 存储/记录的根目录 |
|
|
68
|
+
| `workspaceRoot` | `process.cwd()` | 路径必须解析到该目录内 |
|
|
69
|
+
| `maxBytes` | `20971520` | 文件大小上限(超限即失败,绝不截断) |
|
|
70
|
+
| `maxPixels` | `4000000` | 解码后的像素数上限 |
|
|
71
|
+
| `persist` | `true` | 将图片存为 REP 证据并写入记录 |
|
|
72
|
+
| `blockSize` / `maxShiftBits` | `16` / `6` | 块边长(2–256);位容差(0–blockSize²) |
|
|
73
|
+
| `minVariance` / `nccThreshold` | `6` / `0.97` | 纹理下限;NCC 确认阈值 |
|
|
74
|
+
|
|
75
|
+
## 安全边界
|
|
76
|
+
|
|
77
|
+
- 对图片只读;只在 `root` 下写入。
|
|
78
|
+
- `realpath` 路径包含校验会拒绝符号链接逃逸。
|
|
79
|
+
- 对字节数和像素数设硬上限;像素上限在解压**之前**就根据 IHDR 检查,`inflateSync` 也按预期输出大小加以限制。失败会显式报错。
|
|
80
|
+
- 每次调用的阈值都会校验(`blockSize` 2–256,`maxShiftBits` 0–blockSize²,NCC 0–1);非法阈值返回 `INVALID_INPUT`,不会崩溃。
|
|
81
|
+
- PNG 解析器对每个 chunk 做边界检查;不支持的格式直接拒绝,不做猜测。
|
|
82
|
+
|
|
83
|
+
## 评测
|
|
84
|
+
|
|
85
|
+
**22 个测试**:PNG 往返、非 PNG / 16 位 / 截断文件拒绝、解压前依据 IHDR 拒绝超像素上限(配置值与默认值)、汉明距离与 NCC 基础函数、重复块检测、水平镜像检测、平坦图与渐变图的误报控制、小图的有效块大小、成对匹配、尺寸不一致时拒绝、runtime(合法 REP 记录、每次比较生成两份快照、路径遍历/JPEG/字节与像素超限拒绝、非法阈值拒绝)、tools(schema、check→report、compare、格式错误的报告、失败分支)、包契约。
|
|
86
|
+
|
|
87
|
+
**基准测试状态:尚未声称。** 计划中的 `dsh-research-bench` 数据集是 100 对合成 PNG(重复 / 镜像 / 无关 / 困难负样本)。在该数据集冻结并评分之前,上述单元 fixture 是唯一的证据,README 也如实说明这一点。
|
|
88
|
+
|
|
89
|
+
## 已知限制(v0.1)
|
|
90
|
+
|
|
91
|
+
- 仅支持 PNG;不支持 JPEG/WebP/TIFF。
|
|
92
|
+
- 不抗缩放/旋转/重压缩。
|
|
93
|
+
- 块网格与坐标轴对齐;偏移几个像素的重复区域可能被漏掉。
|
|
94
|
+
- 不分析颜色通道或元数据(EXIF)。
|
|
95
|
+
|
|
96
|
+
## 许可
|
|
97
|
+
|
|
98
|
+
Apache-2.0。运行时不含第三方代码。
|
package/README.md
CHANGED
|
@@ -1,3 +1,101 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-image-integrity
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Is that panel reused — duplicated in place, or pasted mirrored from another figure?**
|
|
4
|
+
|
|
5
|
+
*Zero-dependency PNG decoding, mean-threshold block fingerprints with NCC confirmation, duplicate/mirror region reports, REP evidence and SARIF. It finds reused pixels, not manipulation intent.*
|
|
6
|
+
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
[]()
|
|
9
|
+
|
|
10
|
+
English · [简体中文](README-zh.md)
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## What it does
|
|
15
|
+
|
|
16
|
+
- **`image_check`** — finds a textured block that appears twice (or mirrored) inside one image.
|
|
17
|
+
- **`image_compare`** — finds blocks shared between two images, including mirrored copies.
|
|
18
|
+
- **`image_report`** — Markdown + SARIF 2.1.0, one warning per matched region with coordinates, Hamming distance and NCC.
|
|
19
|
+
|
|
20
|
+
How it works: decode PNG → luma → 16×16 blocks → mean-threshold bit pattern (robust to brightness offsets) + zero-mean NCC confirmation. Blocks that are flat **or close to a fitted plane** are skipped, so a smooth gradient is not reported as "duplicated".
|
|
21
|
+
|
|
22
|
+
## What it does not do
|
|
23
|
+
|
|
24
|
+
- **No JPEG.** Only 8-bit non-interlaced PNG (grey/RGB/RGBA) is decoded. JPEG/16-bit/interlaced are rejected with a clear code — no silent garbage.
|
|
25
|
+
- **No alignment.** Images must have identical dimensions; a mismatch is reported, never resized.
|
|
26
|
+
- **No blur/compression robustness.** JPEG recompression, scaling, rotation or splice blending will usually defeat it.
|
|
27
|
+
- **No misconduct claim.** Repeated controls, scale bars, icons and background texture are legitimate shared blocks. The report says so.
|
|
28
|
+
- **No GUI, no upload.** Local bytes only.
|
|
29
|
+
|
|
30
|
+
## Tools
|
|
31
|
+
|
|
32
|
+
### `image_check`
|
|
33
|
+
|
|
34
|
+
`{ path, persist?, blockSize?, maxShiftBits?, minVariance?, nccThreshold? }` → `{ ok, analysis, evidenceId?, recordPath? }`.
|
|
35
|
+
|
|
36
|
+
### `image_compare`
|
|
37
|
+
|
|
38
|
+
`{ pathA, pathB, persist?, ...thresholds }` → `{ ok, analysis, evidenceId?, recordPath? }`.
|
|
39
|
+
|
|
40
|
+
### `image_report`
|
|
41
|
+
|
|
42
|
+
`{ analysis, imageId? }` → `{ ok, markdown, sarif }`.
|
|
43
|
+
|
|
44
|
+
### Error codes
|
|
45
|
+
|
|
46
|
+
`INVALID_INPUT` · `NOT_FOUND` · `PATH_ESCAPE` · `NOT_A_FILE` · `TOO_LARGE` · `UNSUPPORTED_IMAGE` · `STORE_ERROR`
|
|
47
|
+
|
|
48
|
+
## Compatibility & install
|
|
49
|
+
|
|
50
|
+
| | |
|
|
51
|
+
|---|---|
|
|
52
|
+
| DeepSeek Harness | **`dsh-v0.2.1-rc.5`** (verified 2026-11-08); peer `>=0.2.1-0 <0.3.0 \|\| >=0.2.2-0 <0.3.0` |
|
|
53
|
+
| Node | `^22.19.0 \|\| >=24.9.0` (tested `24.22.1`), ESM only |
|
|
54
|
+
| Peers | `@perrylink/dsh-research-core ^0.1.0`, `@deepseek-ai/cordis ^4.0.5-alpha.1`, `@deepseek-ai/dsh-tools`, `@deepseek-ai/schemastery ^3.18.5-alpha.1` |
|
|
55
|
+
| Runtime dependencies | **zero** (PNG via `node:zlib`) |
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
dsh plugin --profile <name> add @perrylink/dsh-research-core dsh-image-integrity
|
|
59
|
+
dsh --profile <name> --dump-config | grep dsh-image-integrity
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Configuration
|
|
63
|
+
|
|
64
|
+
| Key | Default | Meaning |
|
|
65
|
+
|---|---|---|
|
|
66
|
+
| `enabled` | `true` | `false` mounts nothing |
|
|
67
|
+
| `root` | `.image-integrity` | store/record root |
|
|
68
|
+
| `workspaceRoot` | `process.cwd()` | paths must resolve inside it |
|
|
69
|
+
| `maxBytes` | `20971520` | file cap (fails, never truncates) |
|
|
70
|
+
| `maxPixels` | `4000000` | decoded pixel cap |
|
|
71
|
+
| `persist` | `true` | store images as REP evidence + record |
|
|
72
|
+
| `blockSize` / `maxShiftBits` | `16` / `6` | block side (2–256); bit tolerance (0–blockSize²) |
|
|
73
|
+
| `minVariance` / `nccThreshold` | `6` / `0.97` | texture floor; NCC confirmation |
|
|
74
|
+
|
|
75
|
+
## Security boundaries
|
|
76
|
+
|
|
77
|
+
- Read-only on images; writes only under `root`.
|
|
78
|
+
- `realpath` containment rejects symlink escapes.
|
|
79
|
+
- Hard caps on bytes and pixels; the pixel cap is checked from the IHDR
|
|
80
|
+
**before** inflation, and `inflateSync` is bounded by the expected output
|
|
81
|
+
size. Failures are loud.
|
|
82
|
+
- Per-call thresholds are validated (`blockSize` 2–256, `maxShiftBits`
|
|
83
|
+
0–blockSize², NCC 0–1); an invalid threshold is `INVALID_INPUT`, not a crash.
|
|
84
|
+
- PNG parser bounds-checks every chunk; unsupported formats are rejected, not guessed.
|
|
85
|
+
|
|
86
|
+
## Evaluation
|
|
87
|
+
|
|
88
|
+
**22 tests**: PNG round-trip, non-PNG / 16-bit / truncated rejection, pixel-cap rejection from the IHDR before inflation (configured and default), Hamming and NCC primitives, duplicate block detection, horizontal mirror detection, flat-image and gradient false-positive controls, small-image effective block size, pair matching, dimension-mismatch refusal, runtime (valid REP record, two snapshots per comparison, traversal/JPEG/byte-and-pixel oversize rejection, invalid threshold rejection), tools (schemas, check→report, compare, malformed report, failure branch), package contract.
|
|
89
|
+
|
|
90
|
+
**Benchmark status: not yet claimed.** The planned `dsh-research-bench` set is 100 synthetic PNG pairs (duplicate / mirrored / unrelated / hard negative). Until that set is frozen and scored, the unit fixtures above are the only evidence, and the README says so.
|
|
91
|
+
|
|
92
|
+
## Known limitations (v0.1)
|
|
93
|
+
|
|
94
|
+
- PNG-only; no JPEG/WebP/TIFF.
|
|
95
|
+
- No scaling/rotation/recompression robustness.
|
|
96
|
+
- Block grid is axis-aligned; a duplicated region shifted by a few pixels can be missed.
|
|
97
|
+
- No colour-channel or metadata (EXIF) analysis.
|
|
98
|
+
|
|
99
|
+
## License
|
|
100
|
+
|
|
101
|
+
Apache-2.0. No third-party runtime code.
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# dsh-image-integrity bundle patch: mount the image integrity tools.
|
|
2
|
+
#
|
|
3
|
+
# Every key below is a Config field (Schemastery schema); invalid values fail the
|
|
4
|
+
# profile load loudly. Analysis is local; nothing is uploaded.
|
|
5
|
+
- insert:
|
|
6
|
+
- id: dsh-image-integrity
|
|
7
|
+
name: dsh-image-integrity
|
|
8
|
+
config:
|
|
9
|
+
enabled: true
|
|
10
|
+
root: .image-integrity
|
|
11
|
+
# 20 MiB file cap and 4 MP pixel cap; over-limit fails, never truncated.
|
|
12
|
+
maxBytes: 20971520
|
|
13
|
+
maxPixels: 4000000
|
|
14
|
+
persist: true
|
|
15
|
+
# Detection defaults (block side, bit tolerance of 256, flat-block floor,
|
|
16
|
+
# NCC confirmation threshold).
|
|
17
|
+
blockSize: 16
|
|
18
|
+
maxShiftBits: 6
|
|
19
|
+
minVariance: 6
|
|
20
|
+
nccThreshold: 0.97
|
package/lib/analyze.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Block-level duplication and mirroring detection.
|
|
3
|
+
*
|
|
4
|
+
* Each block is reduced to a mean-threshold bit pattern (robust to additive
|
|
5
|
+
* brightness changes) plus its zero-mean normalised correlation (NCC) for
|
|
6
|
+
* confirmation. Blocks with too little variance (flat backgrounds) are skipped,
|
|
7
|
+
* which is the main defence against false positives on uniform areas.
|
|
8
|
+
*
|
|
9
|
+
* This detects **reused pixels**, not manipulation intent: a duplicated control
|
|
10
|
+
* panel is normal, a duplicated experimental panel usually is not. The report
|
|
11
|
+
* always says which regions matched and at what score.
|
|
12
|
+
*
|
|
13
|
+
* @module dsh-image-integrity/analyze
|
|
14
|
+
*/
|
|
15
|
+
import type { RgbaImage } from './png.ts';
|
|
16
|
+
/** Options shared by single-image and pair analysis. */
|
|
17
|
+
export interface ImageOptions {
|
|
18
|
+
/** Block side in pixels (default 16). */
|
|
19
|
+
readonly blockSize?: number;
|
|
20
|
+
/** Maximum Hamming distance on the block bit pattern (default 6 of 256). */
|
|
21
|
+
readonly maxShiftBits?: number;
|
|
22
|
+
/** Minimum block variance; flatter blocks are ignored (default 6). */
|
|
23
|
+
readonly minVariance?: number;
|
|
24
|
+
/** NCC confirmation threshold (default 0.97). */
|
|
25
|
+
readonly nccThreshold?: number;
|
|
26
|
+
}
|
|
27
|
+
/** A matched region. */
|
|
28
|
+
export interface RegionMatch {
|
|
29
|
+
readonly kind: 'duplicate' | 'horizontal-flip' | 'vertical-flip';
|
|
30
|
+
readonly a: {
|
|
31
|
+
readonly x: number;
|
|
32
|
+
readonly y: number;
|
|
33
|
+
readonly block: number;
|
|
34
|
+
};
|
|
35
|
+
readonly b: {
|
|
36
|
+
readonly x: number;
|
|
37
|
+
readonly y: number;
|
|
38
|
+
readonly block: number;
|
|
39
|
+
};
|
|
40
|
+
readonly hamming: number;
|
|
41
|
+
readonly ncc: number;
|
|
42
|
+
}
|
|
43
|
+
/** Result of analysing one image. */
|
|
44
|
+
export interface ImageAnalysis {
|
|
45
|
+
readonly width: number;
|
|
46
|
+
readonly height: number;
|
|
47
|
+
readonly blockSize: number;
|
|
48
|
+
readonly blocks: number;
|
|
49
|
+
readonly considered: number;
|
|
50
|
+
readonly matches: readonly RegionMatch[];
|
|
51
|
+
readonly duplicatePairs: number;
|
|
52
|
+
readonly flippedPairs: number;
|
|
53
|
+
readonly warnings: readonly string[];
|
|
54
|
+
}
|
|
55
|
+
/** Result of comparing two images. */
|
|
56
|
+
export interface PairAnalysis {
|
|
57
|
+
readonly a: {
|
|
58
|
+
readonly width: number;
|
|
59
|
+
readonly height: number;
|
|
60
|
+
};
|
|
61
|
+
readonly b: {
|
|
62
|
+
readonly width: number;
|
|
63
|
+
readonly height: number;
|
|
64
|
+
};
|
|
65
|
+
readonly matches: readonly RegionMatch[];
|
|
66
|
+
readonly duplicatePairs: number;
|
|
67
|
+
readonly flippedPairs: number;
|
|
68
|
+
readonly warnings: readonly string[];
|
|
69
|
+
}
|
|
70
|
+
/** Convert to luma. */
|
|
71
|
+
export declare function toGray(image: RgbaImage): Float64Array;
|
|
72
|
+
/**
|
|
73
|
+
* Hamming distance between two bit arrays.
|
|
74
|
+
* @param left - first bits.
|
|
75
|
+
* @param right - second bits.
|
|
76
|
+
* @param limit - stop early once the distance exceeds this (default: exact).
|
|
77
|
+
* @returns the exact distance, or a value greater than `limit`.
|
|
78
|
+
*/
|
|
79
|
+
export declare function hamming(left: Uint8Array, right: Uint8Array, limit?: number): number;
|
|
80
|
+
/** Zero-mean NCC of two equal-length vectors. */
|
|
81
|
+
export declare function ncc(left: Float64Array, right: Float64Array): number;
|
|
82
|
+
/**
|
|
83
|
+
* Fill defaults and validate thresholds.
|
|
84
|
+
*
|
|
85
|
+
* Validation lives here (not only in the runtime) because `analyzeImage` and
|
|
86
|
+
* `compareImages` are exported: `blockSize: 0` would otherwise divide by zero
|
|
87
|
+
* and loop forever, and a negative/NaN variance or out-of-range NCC threshold
|
|
88
|
+
* would silently change every result.
|
|
89
|
+
* @param options - caller overrides.
|
|
90
|
+
* @returns fully resolved options.
|
|
91
|
+
*/
|
|
92
|
+
export declare function resolveImageOptions(options?: ImageOptions): Required<ImageOptions>;
|
|
93
|
+
/**
|
|
94
|
+
* Analyse one image for reused blocks and mirrored copies.
|
|
95
|
+
* @param image - decoded image.
|
|
96
|
+
* @param options - detection thresholds.
|
|
97
|
+
* @returns matches and counts.
|
|
98
|
+
*/
|
|
99
|
+
export declare function analyzeImage(image: RgbaImage, options?: ImageOptions): ImageAnalysis;
|
|
100
|
+
/**
|
|
101
|
+
* Compare two images block by block.
|
|
102
|
+
* @param left - first image.
|
|
103
|
+
* @param right - second image.
|
|
104
|
+
* @param options - detection thresholds.
|
|
105
|
+
* @returns cross-image matches and counts.
|
|
106
|
+
*/
|
|
107
|
+
export declare function compareImages(left: RgbaImage, right: RgbaImage, options?: ImageOptions): PairAnalysis;
|
|
108
|
+
//# sourceMappingURL=analyze.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyze.d.ts","sourceRoot":"","sources":["../src/analyze.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEzC,wDAAwD;AACxD,MAAM,WAAW,YAAY;IAC3B,yCAAyC;IACzC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,4EAA4E;IAC5E,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAA;IAC9B,sEAAsE;IACtE,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;IAC7B,iDAAiD;IACjD,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAC/B;AAED,wBAAwB;AACxB,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,WAAW,GAAG,iBAAiB,GAAG,eAAe,CAAA;IAChE,QAAQ,CAAC,CAAC,EAAE;QAAE,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IAC9E,QAAQ,CAAC,CAAC,EAAE;QAAE,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IAC9E,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CACrB;AAED,qCAAqC;AACrC,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,OAAO,EAAE,SAAS,WAAW,EAAE,CAAA;IACxC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;CACrC;AAED,sCAAsC;AACtC,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,CAAC,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;IAC/D,QAAQ,CAAC,CAAC,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;IAC/D,QAAQ,CAAC,OAAO,EAAE,SAAS,WAAW,EAAE,CAAA;IACxC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;CACrC;AAkBD,uBAAuB;AACvB,wBAAgB,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,YAAY,CAOrD;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,SAA2B,GAAG,MAAM,CAWrG;AAED,iDAAiD;AACjD,wBAAgB,GAAG,CAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,GAAG,MAAM,CAsBnE;AA2HD;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,YAAiB,GAAG,QAAQ,CAAC,YAAY,CAAC,CActF;AAiBD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,GAAE,YAAiB,GAAG,aAAa,CA8BxF;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,GAAE,YAAiB,GAAG,YAAY,CAkCzG"}
|