diff options
| author | mtg0001 <106211915+mtg0001@users.noreply.github.com> | 2026-07-31 16:05:35 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-07-31 16:05:35 -0300 |
| commit | 59777ee34a5ab6297684b7ab8d5d93facd4ad6f3 (patch) | |
| tree | 2a471982436dd64eec993ecaad97c7baeae1286a /src/main.cpp | |
| parent | e2d5c1bbe01370dbf75e2118d697a159c4ee582b (diff) | |
net: bound what a peer can make the node allocate (#73)
Three independent bounds on what an untrusted peer can make this node allocate:
- serialize.h: reject a compact size above MAX_SIZE before reading a string or a
vector, instead of discovering it read by read. MAX_SIZE moves from main.h to
serialize.h, where the checks live; headers_core.h includes serialize.h first,
so every existing user still sees it.
- main.cpp: cap an orphan transaction at 10,000 inputs. Orphans are stored and
never validated, so mapOrphanTransactionsByPrev grew with one entry per input
of every orphan a peer cared to send.
- rpc.cpp: drop a Stratum line nested deeper than 20 before json::parse recurses
into it. The scan tracks string state, so a worker name containing { or [ is
no longer mistaken for nesting.
Verified: builds clean on UCRT64; the depth scanner passes a table of legitimate
Stratum lines and nesting attacks; a node built from this branch synced the chain
from genesis to 4462 with no deserialization failure and no rejected block.
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp index 4bc9c4d..c3fb33b 100644 --- a/src/main.cpp +++ b/src/main.cpp | |||
| @@ -282,6 +282,16 @@ void AddOrphanTx(const CDataStream& vMsg) | |||
| 282 | uint256 hash = tx.GetHash(); | 282 | uint256 hash = tx.GetHash(); |
| 283 | if (mapOrphanTransactions.count(hash)) | 283 | if (mapOrphanTransactions.count(hash)) |
| 284 | return; | 284 | return; |
| 285 | |||
| 286 | // Do not allow an orphan to have an unbounded number of inputs. | ||
| 287 | // 10,000 inputs is enough for massive legitimate sweeps, but bounds the total | ||
| 288 | // memory in mapOrphanTransactionsByPrev to ~10,000 * MAX_ORPHAN_TRANSACTIONS. | ||
| 289 | if (tx.vin.size() > 10000) | ||
| 290 | { | ||
| 291 | if (LogAcceptsCategory("net")) printf("AddOrphanTx() : orphan with %d inputs rejected\n", (int)tx.vin.size()); | ||
| 292 | return; | ||
| 293 | } | ||
| 294 | |||
| 285 | CDataStream* pvMsg = mapOrphanTransactions[hash] = new CDataStream(vMsg); | 295 | CDataStream* pvMsg = mapOrphanTransactions[hash] = new CDataStream(vMsg); |
| 286 | foreach(const CTxIn& txin, tx.vin) | 296 | foreach(const CTxIn& txin, tx.vin) |
| 287 | mapOrphanTransactionsByPrev.insert(make_pair(txin.prevout.hash, pvMsg)); | 297 | mapOrphanTransactionsByPrev.insert(make_pair(txin.prevout.hash, pvMsg)); |