summaryrefslogtreecommitdiff
path: root/src/io/stream_reader.cpp
diff options
context:
space:
mode:
authorTheKodeToad <TheKodeToad@proton.me>2023-11-06 16:06:54 +0000
committerGitHub <noreply@github.com>2023-11-06 16:06:54 +0000
commit23b955121b8217c1c348a9ed2483167a6f3ff4ad (patch)
treefdfdf6328a8ca9d648f47297d20474b1d842987c /src/io/stream_reader.cpp
parenta5e8fd52b8bf4ab5d5bcc042b2a247867589985f (diff)
parent3554a63406187b9dac5f72647644527f7fc3396b (diff)
downloadProject-Tick-23b955121b8217c1c348a9ed2483167a6f3ff4ad.tar.gz
Project-Tick-23b955121b8217c1c348a9ed2483167a6f3ff4ad.zip
Merge pull request #3 from TheKodeToad/max-depth-attempt2
Limit recursion, attempt 2
Diffstat (limited to 'src/io/stream_reader.cpp')
-rw-r--r--src/io/stream_reader.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/io/stream_reader.cpp b/src/io/stream_reader.cpp
index f6f30a5b49..28c1e1d89f 100644
--- a/src/io/stream_reader.cpp
+++ b/src/io/stream_reader.cpp
@@ -27,6 +27,8 @@ namespace nbt
namespace io
{
+static constexpr int MAX_DEPTH = 1024;
+
std::pair<std::string, std::unique_ptr<tag_compound>> read_compound(std::istream& is, endian::endian e)
{
return stream_reader(is, e).read_compound();
@@ -74,8 +76,11 @@ std::pair<std::string, std::unique_ptr<tag>> stream_reader::read_tag()
std::unique_ptr<tag> stream_reader::read_payload(tag_type type)
{
+ if (++depth > MAX_DEPTH)
+ throw input_error("Too deeply nested");
std::unique_ptr<tag> t = tag::create(type);
t->read_payload(*this);
+ --depth;
return t;
}