diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/serialize.h | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/serialize.h b/src/serialize.h index 0e03cf7..ce72c60 100644 --- a/src/serialize.h +++ b/src/serialize.h | |||
| @@ -390,10 +390,26 @@ void Serialize(Stream& os, const basic_string<C>& str, int, int) | |||
| 390 | template<typename Stream, typename C> | 390 | template<typename Stream, typename C> |
| 391 | void Unserialize(Stream& is, basic_string<C>& str, int, int) | 391 | void Unserialize(Stream& is, basic_string<C>& str, int, int) |
| 392 | { | 392 | { |
| 393 | // Grow in steps as the bytes actually arrive, the same way the vector | ||
| 394 | // unserializer below does. Resizing straight to the declared length lets | ||
| 395 | // nine bytes on the wire ask for a four-gigabyte allocation, and | ||
| 396 | // ReadCompactSize has no ceiling of its own. | ||
| 397 | // | ||
| 398 | // No network message carries a string today -- CWalletTx::mapValue is the | ||
| 399 | // only string field on a serialized type and RelayMessage casts it away -- | ||
| 400 | // so this is a guard against the next one that does, not a live hole. | ||
| 393 | unsigned int nSize = ReadCompactSize(is); | 401 | unsigned int nSize = ReadCompactSize(is); |
| 394 | str.resize(nSize); | 402 | str.clear(); |
| 395 | if (nSize != 0) | 403 | unsigned int nMid = 0; |
| 396 | is.read((char*)&str[0], nSize * sizeof(str[0])); | 404 | while (nMid < nSize) |
| 405 | { | ||
| 406 | nMid += 5000000 / sizeof(C); | ||
| 407 | if (nMid > nSize) | ||
| 408 | nMid = nSize; | ||
| 409 | unsigned int nOld = str.size(); | ||
| 410 | str.resize(nMid); | ||
| 411 | is.read((char*)&str[nOld], (nMid - nOld) * sizeof(C)); | ||
| 412 | } | ||
| 397 | } | 413 | } |
| 398 | 414 | ||
| 399 | 415 | ||