upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/serialize.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/serialize.h')
-rw-r--r--src/serialize.h8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/serialize.h b/src/serialize.h
index ce72c60..fa77074 100644
--- a/src/serialize.h
+++ b/src/serialize.h
@@ -20,7 +20,7 @@ class CDataStream;
20class CAutoFile; 20class CAutoFile;
21 21
22static const int VERSION = 101; 22static const int VERSION = 101;
23 23static const unsigned int MAX_SIZE = 0x02000000;
24 24
25 25
26 26
@@ -399,6 +399,8 @@ void Unserialize(Stream& is, basic_string<C>& str, int, int)
399 // only string field on a serialized type and RelayMessage casts it away -- 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. 400 // so this is a guard against the next one that does, not a live hole.
401 unsigned int nSize = ReadCompactSize(is); 401 unsigned int nSize = ReadCompactSize(is);
402 if (nSize > MAX_SIZE)
403 throw std::ios_base::failure("String size too large");
402 str.clear(); 404 str.clear();
403 unsigned int nMid = 0; 405 unsigned int nMid = 0;
404 while (nMid < nSize) 406 while (nMid < nSize)
@@ -472,6 +474,8 @@ void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion,
472 // Limit size per read so bogus size value won't cause out of memory 474 // Limit size per read so bogus size value won't cause out of memory
473 v.clear(); 475 v.clear();
474 unsigned int nSize = ReadCompactSize(is); 476 unsigned int nSize = ReadCompactSize(is);
477 if (nSize > MAX_SIZE)
478 throw std::ios_base::failure("Vector size too large");
475 unsigned int i = 0; 479 unsigned int i = 0;
476 while (i < nSize) 480 while (i < nSize)
477 { 481 {
@@ -492,6 +496,8 @@ void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion,
492 496
493 v.clear(); 497 v.clear();
494 unsigned int nSize = ReadCompactSize(is); 498 unsigned int nSize = ReadCompactSize(is);
499 if (nSize > MAX_SIZE)
500 throw std::ios_base::failure("Vector size too large");
495 unsigned int i = 0; 501 unsigned int i = 0;
496 unsigned int nMid = 0; 502 unsigned int nMid = 0;
497 while (nMid < nSize) 503 while (nMid < nSize)