Skip to content

0.97-RC1: two zc-parser crashes on obfuscated block files #778

Description

@tomrobbo

Hit these two running DB manually on RC1 from source on aarch64 against an obfuscated Core 31 datadir - suggested fixes below, both tested.

1. getRawBlockData truncates xor key to 1 byte

BlockchainData.cpp, xor branch:

for (auto& chunk : xoredData)   // uint8_t&
   chunk ^= xorkey;             // ^= (uint8_t)xorkey  -> key[0] only

Garbage for any non-uniform key -> deserialize throws -> failed to grab tx.
Scan path (FileCopy::xorMe) is correct, so only on-demand reads (getTx, zc
parse) break. Suggested fix:

-      for (auto& chunk : xoredData)
-         chunk ^= xorkey;
+      auto data64 = reinterpret_cast<uint64_t*>(xoredData.data());
+      for (size_t i = 0; i < xoredData.size() / 8; i++)
+         data64[i] ^= xorkey;

2. zc parser aborts on unresolved parent

In preprocessTx, getTxOutCopy throws range_error ("index out of bound:
1879 out of 3"), no barrier up to the thread loop -> terminate. range_error is
caught elsewhere in the module but not here. Suggested fix:

-      auto parentTx = bd->getTx(opRef.getDbKey());
-      auto txOut = parentTx.getTxOutCopy(opRef.getIndex());
-      txIn.scrAddr = txOut.getScrAddress();
-      txIn.value = txOut.getAmount();
+      try {
+         auto parentTx = bd->getTx(opRef.getDbKey());
+         auto txOut = parentTx.getTxOutCopy(opRef.getIndex());
+         txIn.scrAddr = txOut.getScrAddress();
+         txIn.value = txOut.getAmount();
+      } catch (const std::exception& e) {
+         LOGWARN << "preprocessTx: skipping input " << iin << ": " << e.what();
+         continue;
+      }

Both verified on aarch64: 1 by moving past where it crashed originally, 2 by fault injection.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions