Skip to content

Commit

Permalink
Reverse both live_sync updates
Browse files Browse the repository at this point in the history
Reverse both live_sync updates
  • Loading branch information
zachhildreth authored Mar 20, 2021
1 parent 4dca79d commit fa66a2c
Showing 1 changed file with 1 addition and 34 deletions.
35 changes: 1 addition & 34 deletions contrib/epee/include/storages/portable_storage_from_bin.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,11 @@
#else
#define EPEE_PORTABLE_STORAGE_RECURSION_LIMIT_INTERNAL 100
#endif
#define EPEE_PORTABLE_STORAGE_OBJECT_LIMIT_INTERNAL 65536
#define EPEE_PORTABLE_STORAGE_ARRAY_ELEMENT_LIMIT_INTERNAL 65536

namespace epee
{
namespace serialization
{
template<typename T>
struct ps_min_bytes {
static constexpr const size_t strict = 4096; // actual low bound
static constexpr const size_t rough = 4096; // when we want to be stricter for DoS prevention
};
template<> struct ps_min_bytes<uint64_t> { static constexpr const size_t strict = 8, rough = 8; };
template<> struct ps_min_bytes<int64_t> { static constexpr const size_t strict = 8, rough = 8; };
template<> struct ps_min_bytes<uint32_t> { static constexpr const size_t strict = 4, rough = 4; };
template<> struct ps_min_bytes<int32_t> { static constexpr const size_t strict = 4, rough = 4; };
template<> struct ps_min_bytes<uint16_t> { static constexpr const size_t strict = 2, rough = 2; };
template<> struct ps_min_bytes<int16_t> { static constexpr const size_t strict = 2, rough = 2; };
template<> struct ps_min_bytes<uint8_t> { static constexpr const size_t strict = 1, rough = 1; };
template<> struct ps_min_bytes<int8_t> { static constexpr const size_t strict = 1, rough = 1; };
template<> struct ps_min_bytes<double> { static constexpr const size_t strict = 8, rough = 8; };
template<> struct ps_min_bytes<bool> { static constexpr const size_t strict = 1, rough = 1; };
template<> struct ps_min_bytes<std::string> { static constexpr const size_t strict = 2, rough = 16; };
template<> struct ps_min_bytes<section> { static constexpr const size_t strict = 1, rough = 256; };
template<> struct ps_min_bytes<array_entry> { static constexpr const size_t strict = 1, rough = 128; };
struct throwable_buffer_reader
{
throwable_buffer_reader(const void* ptr, size_t sz);
Expand All @@ -80,8 +60,6 @@ namespace epee
void read(section& sec);
void read(std::string& str);
void read(array_entry &ae);
template<class t_type>
size_t min_bytes() const;
private:
struct recursuion_limitation_guard
{
Expand All @@ -102,8 +80,6 @@ namespace epee
const uint8_t* m_ptr;
size_t m_count;
size_t m_recursion_count;
size_t m_objects;
size_t m_array_elements;
};

inline throwable_buffer_reader::throwable_buffer_reader(const void* ptr, size_t sz)
Expand All @@ -115,8 +91,6 @@ namespace epee
m_ptr = (uint8_t*)ptr;
m_count = sz;
m_recursion_count = 0;
m_objects = 0;
m_array_elements = 0;
}
inline
void throwable_buffer_reader::read(void* target, size_t count)
Expand Down Expand Up @@ -162,11 +136,7 @@ namespace epee
//for pod types
array_entry_t<type_name> sa;
size_t size = read_varint();
CHECK_AND_ASSERT_THROW_MES(size < EPEE_PORTABLE_STORAGE_ARRAY_ELEMENT_LIMIT_INTERNAL - m_array_elements, "Too many array elements");
m_array_elements += size;
CHECK_AND_ASSERT_THROW_MES(size <= m_count / ps_min_bytes<type_name>::strict, "Size sanity check failed");
const size_t threshold = 16384 - std::min<size_t>(m_array_elements, 16384);
CHECK_AND_ASSERT_THROW_MES(size <= threshold || size <= m_count / ps_min_bytes<type_name>::rough, "Large array stricter size sanity check failed");
CHECK_AND_ASSERT_THROW_MES(size <= m_count, "Invalid");
//TODO: add some optimization here later
while(size--)
sa.m_array.push_back(read<type_name>());
Expand Down Expand Up @@ -290,8 +260,6 @@ namespace epee
RECURSION_LIMITATION();
sec.m_entries.clear();
size_t count = read_varint();
CHECK_AND_ASSERT_THROW_MES(count < EPEE_PORTABLE_STORAGE_OBJECT_LIMIT_INTERNAL - m_objects, "Too many objects");
m_objects += count;
while(count--)
{
//read section name string
Expand Down Expand Up @@ -320,4 +288,3 @@ namespace epee
}
}
}

0 comments on commit fa66a2c

Please sign in to comment.