react-native-update 10.53.1 → 10.54.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.
Files changed (105) hide show
  1. package/README-CN.md +31 -31
  2. package/README.md +31 -31
  3. package/android/jni/HDiffPatch/.travis.yml +33 -0
  4. package/android/jni/HDiffPatch/builds/xcode/bestParams.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  5. package/android/jni/HDiffPatch/builds/xcode/hdiffz.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  6. package/android/jni/HDiffPatch/builds/xcode/hdiffz.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  7. package/android/jni/HDiffPatch/builds/xcode/hpatchz.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  8. package/android/jni/HDiffPatch/builds/xcode/lz4.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  9. package/android/jni/HDiffPatch/builds/xcode/lzma.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  10. package/android/jni/HDiffPatch/builds/xcode/testHashClash.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  11. package/android/jni/HDiffPatch/builds/xcode/testHashClash.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  12. package/android/jni/HDiffPatch/builds/xcode/unitTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  13. package/android/jni/HDiffPatch/builds/xcode/zstd.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  14. package/android/jni/lzma/DOC/7zC.txt +187 -0
  15. package/android/jni/lzma/DOC/7zFormat.txt +469 -0
  16. package/android/jni/lzma/DOC/Methods.txt +173 -0
  17. package/android/jni/lzma/DOC/installer.txt +166 -0
  18. package/android/jni/lzma/DOC/lzma-history.txt +446 -0
  19. package/android/jni/lzma/DOC/lzma-sdk.txt +357 -0
  20. package/android/jni/lzma/DOC/lzma-specification.txt +1176 -0
  21. package/android/jni/lzma/DOC/lzma.txt +328 -0
  22. package/android/jni/lzma/bin/7zS2.sfx +0 -0
  23. package/android/jni/lzma/bin/7zS2con.sfx +0 -0
  24. package/android/jni/lzma/bin/7zSD.sfx +0 -0
  25. package/android/jni/lzma/bin/7zdec.exe +0 -0
  26. package/android/jni/lzma/bin/7zr.exe +0 -0
  27. package/android/jni/lzma/bin/installer/config.txt +5 -0
  28. package/android/jni/lzma/bin/installer/cr.bat +5 -0
  29. package/android/jni/lzma/bin/lzma.exe +0 -0
  30. package/android/jni/lzma/bin/x64/7zr.exe +0 -0
  31. package/android/lib/arm64-v8a/librnupdate.so +0 -0
  32. package/android/lib/armeabi-v7a/librnupdate.so +0 -0
  33. package/android/lib/x86/librnupdate.so +0 -0
  34. package/android/lib/x86_64/librnupdate.so +0 -0
  35. package/android/src/main/java/cn/reactnative/modules/update/ArchiveLimits.java +44 -0
  36. package/android/src/main/java/cn/reactnative/modules/update/DownloadTask.java +124 -40
  37. package/android/src/main/java/cn/reactnative/modules/update/InstallRecord.java +125 -0
  38. package/android/src/main/java/cn/reactnative/modules/update/NativeCheckOrchestrator.java +43 -11
  39. package/android/src/main/java/cn/reactnative/modules/update/NativeUpdateFlow.java +2 -0
  40. package/android/src/main/java/cn/reactnative/modules/update/SafeZipFile.java +90 -0
  41. package/android/src/main/java/cn/reactnative/modules/update/UpdateContext.java +79 -19
  42. package/android/src/main/java/cn/reactnative/modules/update/UpdateFileUtils.java +21 -0
  43. package/android/src/main/java/cn/reactnative/modules/update/UpdateModuleImpl.java +33 -2
  44. package/android/src/main/java/cn/reactnative/modules/update/UpdateModuleSupport.java +1 -0
  45. package/android/src/newarch/cn/reactnative/modules/update/UpdateModule.java +5 -0
  46. package/android/src/oldarch/cn/reactnative/modules/update/UpdateModule.java +5 -0
  47. package/cpp/patch_core/archive_limits.h +38 -0
  48. package/cpp/patch_core/install_record.h +36 -0
  49. package/cpp/update_flow_core/flow_json.h +1 -0
  50. package/cpp/update_flow_core/update_flow_core.cpp +41 -7
  51. package/cpp/update_flow_core/update_flow_core.h +9 -0
  52. package/cpp/update_flow_core/update_flow_jni.cpp +12 -0
  53. package/harmony/pushy/src/main/cpp/PushyTurboModule.cpp +2 -0
  54. package/harmony/pushy/src/main/cpp/pushy.cpp +37 -0
  55. package/harmony/pushy/src/main/ets/ArchiveLimits.ts +83 -0
  56. package/harmony/pushy/src/main/ets/DownloadTask.ts +126 -30
  57. package/harmony/pushy/src/main/ets/InstallRecord.ts +129 -0
  58. package/harmony/pushy/src/main/ets/NativeCheckOrchestrator.ts +24 -2
  59. package/harmony/pushy/src/main/ets/NativePatchCore.ts +5 -0
  60. package/harmony/pushy/src/main/ets/PushyTurboModule.ts +12 -0
  61. package/harmony/pushy/src/main/ets/UpdateContext.ts +78 -15
  62. package/harmony/pushy.har +0 -0
  63. package/ios/RCTPushy/RCTPushy.mm +384 -25
  64. package/ios/RCTPushy/RCTPushyDownloader.mm +32 -0
  65. package/package.json +25 -2
  66. package/src/NativePushy.ts +13 -0
  67. package/src/client.ts +160 -43
  68. package/src/core.ts +17 -3
  69. package/src/error.ts +3 -0
  70. package/src/index.ts +8 -0
  71. package/src/locales/en.ts +3 -0
  72. package/src/locales/zh.ts +2 -0
  73. package/src/metadata.ts +166 -0
  74. package/src/provider.tsx +52 -17
  75. package/src/type.ts +22 -0
  76. package/src/updateFlowCore.ts +95 -4
  77. package/src/utils.ts +31 -19
  78. package/.gitmodules +0 -6
  79. package/BUNDLEHASH_MIGRATION.md +0 -355
  80. package/NATIVE_CHECKUPDATE_DESIGN.md +0 -539
  81. package/NATIVE_CHECK_FOLLOWUPS.md +0 -514
  82. package/android/jni/HDiffPatch/test/_private_searchBestParams.cpp +0 -301
  83. package/android/jni/HDiffPatch/test/hpatchz_test.cpp +0 -292
  84. package/android/jni/HDiffPatch/test/testHashClash.cpp +0 -436
  85. package/android/jni/HDiffPatch/test/unit_test.cpp +0 -417
  86. package/biome.json +0 -59
  87. package/cpp/patch_core/tests/fixtures/rawstored.lzma2label.patch.bin +0 -0
  88. package/cpp/patch_core/tests/fixtures/rawstored.new.bin +0 -0
  89. package/cpp/patch_core/tests/fixtures/rawstored.old.bin +0 -0
  90. package/cpp/patch_core/tests/fixtures/v96.hbc +0 -0
  91. package/cpp/patch_core/tests/fixtures/v96.meta.json +0 -1
  92. package/cpp/patch_core/tests/fixtures/v96.streampatch.bin +0 -0
  93. package/cpp/patch_core/tests/fixtures/v96.t.hbc +0 -0
  94. package/cpp/patch_core/tests/fixtures/v96.tpatch.bin +0 -0
  95. package/cpp/patch_core/tests/fixtures/v96.tstreampatch.bin +0 -0
  96. package/cpp/patch_core/tests/fixtures/v96b.hbc +0 -0
  97. package/cpp/patch_core/tests/fixtures/v98.hbc +0 -0
  98. package/cpp/patch_core/tests/fixtures/v98.t.hbc +0 -0
  99. package/cpp/patch_core/tests/fixtures/v98b.hbc +0 -0
  100. package/cpp/patch_core/tests/fixtures/v98b.t.hbc +0 -0
  101. package/cpp/patch_core/tests/hbc_transform_test.cpp +0 -384
  102. package/cpp/patch_core/tests/patch_core_test.cpp +0 -970
  103. package/cpp/update_flow_core/tests/flow_vectors.json +0 -1401
  104. package/cpp/update_flow_core/tests/update_flow_core_test.cpp +0 -317
  105. package/scripts/check-expo-version.js +0 -92
@@ -1,384 +0,0 @@
1
- // hbc_transform 宿主机测试:
2
- // 1) 与 JS 参考实现(react-native-update-cli src/utils/hbcTransform.ts)
3
- // 做 golden 对拍——fixtures/*.t.hbc 由 JS 实现生成;
4
- // 2) 可逆性 property check;
5
- // 3) 非法输入/非法描述表拒绝(buffer 必须保持原样);
6
- // 4) wire 解析器(ParseHbcTransformMeta/BuildLayout)的正向/负向直测——
7
- // 它解析的是随 patch 下发的不可信输入,拒绝分支必须逐条有覆盖。
8
- #include "../hbc_transform.h"
9
- #include "../hbc_transform_wire.h"
10
-
11
- #include <cstdio>
12
- #include <cstring>
13
- #include <fstream>
14
- #include <string>
15
- #include <vector>
16
-
17
- namespace {
18
-
19
- using pushy::hbc::BuildLayout;
20
- using pushy::hbc::HbcDeltaField;
21
- using pushy::hbc::HbcLayoutDesc;
22
- using pushy::hbc::HbcSectionDesc;
23
- using pushy::hbc::HbcTransformMeta;
24
- using pushy::hbc::ParseHbcTransformMeta;
25
- using pushy::hbc::TransformHbcInPlace;
26
-
27
- int g_failures = 0;
28
-
29
- #define CHECK(cond) \
30
- do { \
31
- if (!(cond)) { \
32
- std::fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \
33
- ++g_failures; \
34
- } \
35
- } while (0)
36
-
37
- std::vector<uint8_t> ReadFileOrDie(const std::string& path) {
38
- std::ifstream in(path, std::ios::binary);
39
- if (!in) {
40
- std::fprintf(stderr, "cannot open fixture: %s\n", path.c_str());
41
- std::exit(1);
42
- }
43
- return std::vector<uint8_t>(
44
- (std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
45
- }
46
-
47
- // ---- 布局描述表(测试用常量;生产路径从 patch 元数据的 wire 格式构建)----
48
- // 与 CLI 的 HBC_LAYOUTS 逐字段对应。counts 槽位约定:0 = fileLength,
49
- // 最后一个 = debugInfoOffset。
50
-
51
- const HbcDeltaField kFuncOffset25[] = {{0, 0, 25}};
52
- const HbcDeltaField kFuncOffsets25x2[] = {{0, 0, 25}, {8, 0, 25}};
53
- const HbcDeltaField kStringOffset23[] = {{0, 1, 23}};
54
- const HbcDeltaField kPairOffset32[] = {{0, 0, 32}};
55
-
56
- // v87~v96:19 个计数槽
57
- // [0]fileLength [1]globalCodeIndex [2]functionCount [3]stringKindCount
58
- // [4]identifierCount [5]stringCount [6]overflowStringCount
59
- // [7]stringStorageSize [8]bigIntCount [9]bigIntStorageSize [10]regExpCount
60
- // [11]regExpStorageSize [12]arrayBufferSize [13]objKeyBufferSize
61
- // [14]objValueBufferSize [15]segmentID [16]cjsModuleCount
62
- // [17]functionSourceCount [18]debugInfoOffset
63
- const HbcSectionDesc kSectionsV96[] = {
64
- {2, 16, kFuncOffsets25x2, 2}, // functionHeaders
65
- {3, 4, nullptr, 0}, // stringKinds
66
- {4, 4, nullptr, 0}, // identifierHashes
67
- {5, 4, kStringOffset23, 1}, // smallStringTable
68
- {6, 8, kPairOffset32, 1}, // overflowStringTable
69
- {7, 1, nullptr, 0}, // stringStorage
70
- {12, 1, nullptr, 0}, // arrayBuffer
71
- {13, 1, nullptr, 0}, // objKeyBuffer
72
- {14, 1, nullptr, 0}, // objValueBuffer
73
- {8, 8, kPairOffset32, 1}, // bigIntTable
74
- {9, 1, nullptr, 0}, // bigIntStorage
75
- {10, 8, kPairOffset32, 1}, // regExpTable
76
- {11, 1, nullptr, 0}, // regExpStorage
77
- {16, 8, nullptr, 0}, // cjsModuleTable
78
- {17, 8, nullptr, 0}, // functionSourceTable
79
- };
80
- const HbcLayoutDesc kLayoutV96 = {19, kSectionsV96, 15};
81
-
82
- // v98 早期变体(Static Hermes,19 槽):SmallFuncHeader 12B、
83
- // objShapeTable 取代 objValueBuffer
84
- const HbcSectionDesc kSectionsV98[] = {
85
- {2, 12, kFuncOffset25, 1}, // functionHeaders
86
- {3, 4, nullptr, 0}, // stringKinds
87
- {4, 4, nullptr, 0}, // identifierHashes
88
- {5, 4, kStringOffset23, 1}, // smallStringTable
89
- {6, 8, kPairOffset32, 1}, // overflowStringTable
90
- {7, 1, nullptr, 0}, // stringStorage
91
- {12, 1, nullptr, 0}, // literalValueBuffer
92
- {13, 1, nullptr, 0}, // objKeyBuffer
93
- {14, 8, kPairOffset32, 1}, // objShapeTable
94
- {8, 8, kPairOffset32, 1}, // bigIntTable
95
- {9, 1, nullptr, 0}, // bigIntStorage
96
- {10, 8, kPairOffset32, 1}, // regExpTable
97
- {11, 1, nullptr, 0}, // regExpStorage
98
- {16, 8, nullptr, 0}, // cjsModuleTable
99
- {17, 8, nullptr, 0}, // functionSourceTable
100
- };
101
- const HbcLayoutDesc kLayoutV98 = {19, kSectionsV98, 15};
102
-
103
- // v98 晚期变体(生产主流,20 槽):槽 15 = numStringSwitchImms,
104
- // 其后 segmentID/cjs/functionSource/debugInfo 依次后移一位
105
- const HbcSectionDesc kSectionsV98Late[] = {
106
- {2, 12, kFuncOffset25, 1}, // functionHeaders
107
- {3, 4, nullptr, 0}, // stringKinds
108
- {4, 4, nullptr, 0}, // identifierHashes
109
- {5, 4, kStringOffset23, 1}, // smallStringTable
110
- {6, 8, kPairOffset32, 1}, // overflowStringTable
111
- {7, 1, nullptr, 0}, // stringStorage
112
- {12, 1, nullptr, 0}, // literalValueBuffer
113
- {13, 1, nullptr, 0}, // objKeyBuffer
114
- {14, 8, kPairOffset32, 1}, // objShapeTable
115
- {8, 8, kPairOffset32, 1}, // bigIntTable
116
- {9, 1, nullptr, 0}, // bigIntStorage
117
- {10, 8, kPairOffset32, 1}, // regExpTable
118
- {11, 1, nullptr, 0}, // regExpStorage
119
- {17, 8, nullptr, 0}, // cjsModuleTable
120
- {18, 8, nullptr, 0}, // functionSourceTable
121
- };
122
- const HbcLayoutDesc kLayoutV98Late = {20, kSectionsV98Late, 15};
123
-
124
- void TestGoldenPair(
125
- const std::string& dir,
126
- const char* plainName,
127
- const char* goldenName,
128
- const HbcLayoutDesc& layout) {
129
- const std::vector<uint8_t> plain = ReadFileOrDie(dir + plainName);
130
- const std::vector<uint8_t> golden = ReadFileOrDie(dir + goldenName);
131
- CHECK(plain.size() == golden.size());
132
-
133
- // T(plain) == golden(与 JS 实现逐字节一致)
134
- std::vector<uint8_t> forward = plain;
135
- CHECK(TransformHbcInPlace(forward.data(), forward.size(), layout, false));
136
- CHECK(forward == golden);
137
- CHECK(forward != plain); // 确实改写了字节
138
-
139
- // T⁻¹(golden) == plain
140
- std::vector<uint8_t> backward = golden;
141
- CHECK(TransformHbcInPlace(backward.data(), backward.size(), layout, true));
142
- CHECK(backward == plain);
143
- }
144
-
145
- void TestRejections(const std::string& dir) {
146
- const std::vector<uint8_t> good = ReadFileOrDie(dir + "v98.hbc");
147
-
148
- // 太短
149
- {
150
- std::vector<uint8_t> buf(good.begin(), good.begin() + 64);
151
- CHECK(!TransformHbcInPlace(buf.data(), buf.size(), kLayoutV98, false));
152
- }
153
- // 坏 magic → 拒绝且 buffer 不被修改
154
- {
155
- std::vector<uint8_t> buf = good;
156
- buf[0] ^= 0xff;
157
- const std::vector<uint8_t> before = buf;
158
- CHECK(!TransformHbcInPlace(buf.data(), buf.size(), kLayoutV98, false));
159
- CHECK(buf == before);
160
- }
161
- // fileLength 与实际大小不符(截断)
162
- {
163
- std::vector<uint8_t> buf(good.begin(), good.end() - 8);
164
- const std::vector<uint8_t> before = buf;
165
- CHECK(!TransformHbcInPlace(buf.data(), buf.size(), kLayoutV98, false));
166
- CHECK(buf == before);
167
- }
168
- // 计数爆表 → 段越界
169
- {
170
- std::vector<uint8_t> buf = good;
171
- buf[32 + 2 * 4] = 0xff;
172
- buf[32 + 2 * 4 + 1] = 0xff;
173
- buf[32 + 2 * 4 + 2] = 0xff;
174
- buf[32 + 2 * 4 + 3] = 0x0f;
175
- const std::vector<uint8_t> before = buf;
176
- CHECK(!TransformHbcInPlace(buf.data(), buf.size(), kLayoutV98, false));
177
- CHECK(buf == before);
178
- }
179
- // 非法描述表:countIndex 越界
180
- {
181
- std::vector<uint8_t> buf = good;
182
- const HbcSectionDesc bad[] = {{99, 4, nullptr, 0}};
183
- const HbcLayoutDesc badLayout = {19, bad, 1};
184
- CHECK(!TransformHbcInPlace(buf.data(), buf.size(), badLayout, false));
185
- }
186
- // 非法描述表:差分字段超出条目
187
- {
188
- std::vector<uint8_t> buf = good;
189
- const HbcDeltaField badField[] = {{4, 0, 32}}; // byte 4 + 4 > entrySize 4
190
- const HbcSectionDesc bad[] = {{5, 4, badField, 1}};
191
- const HbcLayoutDesc badLayout = {19, bad, 1};
192
- CHECK(!TransformHbcInPlace(buf.data(), buf.size(), badLayout, false));
193
- }
194
- // 非法描述表:位域越过 32 位
195
- {
196
- std::vector<uint8_t> buf = good;
197
- const HbcDeltaField badField[] = {{0, 8, 25}};
198
- const HbcSectionDesc bad[] = {{5, 4, badField, 1}};
199
- const HbcLayoutDesc badLayout = {19, bad, 1};
200
- CHECK(!TransformHbcInPlace(buf.data(), buf.size(), badLayout, false));
201
- }
202
- // CP2-1 回归:bit=0xFFFFFFFF 时 bit+bits 的 uint32 求和回绕为 0,
203
- // 曾绕过 >32 检查进入改写阶段(移位量 ≥32 的 UB)。必须拒绝且不改字节。
204
- {
205
- std::vector<uint8_t> buf = good;
206
- const std::vector<uint8_t> before = buf;
207
- const HbcDeltaField badField[] = {{0, 0xffffffffu, 1}};
208
- const HbcSectionDesc bad[] = {{5, 4, badField, 1}};
209
- const HbcLayoutDesc badLayout = {19, bad, 1};
210
- CHECK(!TransformHbcInPlace(buf.data(), buf.size(), badLayout, false));
211
- CHECK(buf == before);
212
- }
213
- // bit=31 本身合法,但 bit+bits=33 不回绕也必须拒绝
214
- {
215
- std::vector<uint8_t> buf = good;
216
- const HbcDeltaField badField[] = {{0, 31, 2}};
217
- const HbcSectionDesc bad[] = {{5, 4, badField, 1}};
218
- const HbcLayoutDesc badLayout = {19, bad, 1};
219
- CHECK(!TransformHbcInPlace(buf.data(), buf.size(), badLayout, false));
220
- }
221
- // 非法描述表:bits=0
222
- {
223
- std::vector<uint8_t> buf = good;
224
- const HbcDeltaField badField[] = {{0, 0, 0}};
225
- const HbcSectionDesc bad[] = {{5, 4, badField, 1}};
226
- const HbcLayoutDesc badLayout = {19, bad, 1};
227
- CHECK(!TransformHbcInPlace(buf.data(), buf.size(), badLayout, false));
228
- }
229
- }
230
-
231
- // ---- wire 解析器直测 ----
232
-
233
- std::string ReadTextFileOrDie(const std::string& path) {
234
- const std::vector<uint8_t> raw = ReadFileOrDie(path);
235
- return std::string(raw.begin(), raw.end());
236
- }
237
-
238
- void TestWireParser(const std::string& dir) {
239
- // 正向:真实 fixture 解析 + BuildLayout 后与手写 kLayoutV96 等效
240
- // (对 v96.hbc 变换产物与 golden 逐字节一致 = 端到端等效性证明)
241
- {
242
- HbcTransformMeta meta;
243
- CHECK(ParseHbcTransformMeta(ReadTextFileOrDie(dir + "v96.meta.json"), &meta));
244
- CHECK(meta.v == 1);
245
- CHECK(meta.hbcVersion == 96);
246
- CHECK(meta.headerCountFields == 19);
247
- CHECK(meta.sections.size() == 15);
248
- std::vector<HbcSectionDesc> scratch;
249
- const HbcLayoutDesc layout = BuildLayout(meta, &scratch);
250
- std::vector<uint8_t> buf = ReadFileOrDie(dir + "v96.hbc");
251
- CHECK(TransformHbcInPlace(buf.data(), buf.size(), layout, false));
252
- CHECK(buf == ReadFileOrDie(dir + "v96.t.hbc"));
253
- }
254
-
255
- const std::string minimalLayout =
256
- R"("layout":{"counts":19,"sections":[[5,4,[]]]})";
257
- const std::string minimal =
258
- R"({"v":1,"hbcVersion":96,)" + minimalLayout + "}";
259
-
260
- // 正向:最小合法输入;未知键(各种值形态)被跳过;边界位域 [0,31,1] 合法
261
- {
262
- HbcTransformMeta meta;
263
- CHECK(ParseHbcTransformMeta(minimal, &meta));
264
- CHECK(ParseHbcTransformMeta(
265
- R"({"v":1,"hbcVersion":96,"future":{"a":[1,"s\"x",true,null],"b":-1.5e3},)" +
266
- minimalLayout + "}",
267
- &meta));
268
- CHECK(ParseHbcTransformMeta(
269
- R"({"v":1,"hbcVersion":96,"layout":{"counts":19,"sections":[[5,4,[[0,31,1]]]]}})",
270
- &meta));
271
- CHECK(meta.sections[0].deltaFields[0].bit == 31);
272
- }
273
-
274
- // 负向:每条拒绝分支单测,解析必须返回 false
275
- const char* rejects[] = {
276
- // 非 JSON / 结构破损
277
- "not json",
278
- "",
279
- "{",
280
- R"({"v":1,"hbcVersion":96})", // 缺 layout
281
- R"({"v":1,"layout":{"counts":19,"sections":[[5,4,[]]]}})", // 缺 hbcVersion
282
- R"({"hbcVersion":96,"layout":{"counts":19,"sections":[[5,4,[]]]}})", // 缺 v
283
- R"({"v":1,"hbcVersion":96,"layout":{"counts":19}})", // 缺 sections
284
- R"({"v":1,"hbcVersion":96,"layout":{"sections":[[5,4,[]]]}})", // 缺 counts
285
- R"({"v":1,"hbcVersion":96,"layout":{"counts":19,"sections":[]}})", // 空 sections
286
- R"({"v":1,"hbcVersion":96,"layout":{"counts":0,"sections":[[5,4,[]]]}})", // counts=0
287
- R"({"v":1,"hbcVersion":96,"layout":[1,2]})", // layout 非对象
288
- // 尾部多余内容
289
- R"({"v":1,"hbcVersion":96,"layout":{"counts":19,"sections":[[5,4,[]]]}} x)",
290
- // 键含转义(本格式的键不允许反斜杠;raw string 里 \x 就是两个字符)
291
- R"({"v\x":1,"v":1,"hbcVersion":96,"layout":{"counts":19,"sections":[[5,4,[]]]}})",
292
- // ParseUInt 溢出(>0xffffffff)与负数
293
- R"({"v":4294967296,"hbcVersion":96,"layout":{"counts":19,"sections":[[5,4,[]]]}})",
294
- R"({"v":-1,"hbcVersion":96,"layout":{"counts":19,"sections":[[5,4,[]]]}})",
295
- // 位域语义:CP2-1 的 bit 溢出、bit+bits>32、bits=0、bits=33
296
- R"({"v":1,"hbcVersion":96,"layout":{"counts":19,"sections":[[5,4,[[0,4294967295,1]]]]}})",
297
- R"({"v":1,"hbcVersion":96,"layout":{"counts":19,"sections":[[5,4,[[0,31,2]]]]}})",
298
- R"({"v":1,"hbcVersion":96,"layout":{"counts":19,"sections":[[5,4,[[0,0,0]]]]}})",
299
- R"({"v":1,"hbcVersion":96,"layout":{"counts":19,"sections":[[5,4,[[0,0,33]]]]}})",
300
- // delta field 元组长度不对
301
- R"({"v":1,"hbcVersion":96,"layout":{"counts":19,"sections":[[5,4,[[0,0]]]]}})",
302
- };
303
- for (const char* json : rejects) {
304
- HbcTransformMeta meta;
305
- if (ParseHbcTransformMeta(json, &meta)) {
306
- std::fprintf(stderr, "FAIL: wire parser accepted: %s\n", json);
307
- ++g_failures;
308
- }
309
- }
310
-
311
- // 负向:输入尺寸上限(64KB)
312
- {
313
- std::string huge = minimal;
314
- huge.insert(1, std::string(65 * 1024, ' '));
315
- HbcTransformMeta meta;
316
- CHECK(!ParseHbcTransformMeta(huge, &meta));
317
- }
318
- // 负向:未知键的值嵌套深度超限(kMaxDepth=8)
319
- {
320
- std::string deep = R"({"v":1,"hbcVersion":96,"x":)";
321
- for (int i = 0; i < 12; ++i) deep += '[';
322
- deep += '1';
323
- for (int i = 0; i < 12; ++i) deep += ']';
324
- deep += ',' + minimalLayout + "}";
325
- HbcTransformMeta meta;
326
- CHECK(!ParseHbcTransformMeta(deep, &meta));
327
- }
328
- // 负向:sections 超过 64 个
329
- {
330
- std::string many = R"({"v":1,"hbcVersion":96,"layout":{"counts":19,"sections":[)";
331
- for (int i = 0; i < 65; ++i) {
332
- if (i) many += ',';
333
- many += "[5,4,[]]";
334
- }
335
- many += "]}}";
336
- HbcTransformMeta meta;
337
- CHECK(!ParseHbcTransformMeta(many, &meta));
338
- }
339
- // 负向:单段 deltaFields 超过 8 个
340
- {
341
- std::string many = R"({"v":1,"hbcVersion":96,"layout":{"counts":19,"sections":[[5,64,[)";
342
- for (int i = 0; i < 9; ++i) {
343
- if (i) many += ',';
344
- many += "[0,0,8]";
345
- }
346
- many += "]]]}}";
347
- HbcTransformMeta meta;
348
- CHECK(!ParseHbcTransformMeta(many, &meta));
349
- }
350
- }
351
-
352
- } // namespace
353
-
354
- int main(int argc, char** argv) {
355
- std::string fixturesDir = "cpp/patch_core/tests/fixtures/";
356
- if (argc > 1) {
357
- fixturesDir = argv[1];
358
- if (!fixturesDir.empty() && fixturesDir.back() != '/') {
359
- fixturesDir += '/';
360
- }
361
- }
362
-
363
- TestGoldenPair(fixturesDir, "v96.hbc", "v96.t.hbc", kLayoutV96);
364
- TestGoldenPair(fixturesDir, "v98.hbc", "v98.t.hbc", kLayoutV98);
365
- TestGoldenPair(fixturesDir, "v98b.hbc", "v98b.t.hbc", kLayoutV98Late);
366
- TestRejections(fixturesDir);
367
- TestWireParser(fixturesDir);
368
-
369
- // 变体互斥:19 槽布局作用于 20 槽文件(或反之)必须被结构校验拒绝
370
- {
371
- std::vector<uint8_t> late = ReadFileOrDie(fixturesDir + "v98b.hbc");
372
- CHECK(!TransformHbcInPlace(late.data(), late.size(), kLayoutV98, false));
373
- std::vector<uint8_t> early = ReadFileOrDie(fixturesDir + "v98.hbc");
374
- CHECK(
375
- !TransformHbcInPlace(early.data(), early.size(), kLayoutV98Late, false));
376
- }
377
-
378
- if (g_failures > 0) {
379
- std::fprintf(stderr, "hbc_transform_test: %d failure(s)\n", g_failures);
380
- return 1;
381
- }
382
- std::printf("hbc_transform_test: all checks passed\n");
383
- return 0;
384
- }