فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

test(a02): reject malicious central CRC mismatch and remove staged partial backup

davoodmehraban89 committed Oct 30, 2026 at 19:19 UTC ade93c99a7ce464bdb682d4d318dbda10adef73f
1 file changed +20
scripts/a02-private-holoo-zip-staging.cs
+20
@@ -229,6 +229,26 @@ namespace Finora.Migration {
229 try { Stage(good, outFile); }
230 catch (IOException) { refusedOverwrite = true; }
231 Require(refusedOverwrite, "A02_OVERWRITE_ALLOWED");
232 + // Mutate ONLY central CRC, leaving compressed source bytes intact:
233 + // probing must not claim CRC, and staging must fail and clean up.
234 + string damaged = Path.Combine(root, "bad_crc.zip");
235 + byte[] corrupt = File.ReadAllBytes(good);
236 + int central = -1;
237 + for (int i = 0; i <= corrupt.Length - 46; i++) {
238 + if (BitConverter.ToUInt32(corrupt, i) == 0x02014b50u) { central = i; break; }
239 + }
240 + Require(central >= 0, "A02_SYNTHETIC_CENTRAL_MISSING");
241 + corrupt[central + 16] ^= 0x80;
242 + File.WriteAllBytes(damaged, corrupt);
243 + HolooZipReport badProbe = Probe(damaged);
244 + Require(badProbe.EnvelopeValid && !badProbe.CrcVerified,
245 + "A02_PROBE_MUST_NOT_CLAIM_CRC");
246 + string damagedOut = Path.Combine(root, "bad_crc.bak");
247 + bool crcBlocked = false;
248 + try { Stage(damaged, damagedOut); }
249 + catch (InvalidDataException) { crcBlocked = true; }
250 + Require(crcBlocked && !File.Exists(damagedOut),
251 + "A02_CORRUPTED_CRC_ACCEPTED_OR_OUTPUT_LEFT");
252 string wrong = Path.Combine(root, "not_sql.zip");
253 using (FileStream f = new FileStream(wrong, FileMode.CreateNew)) {
254 using (ZipArchive zip = new ZipArchive(f, ZipArchiveMode.Create, true)) {