From 37084afebfb09b30126f26eb64e508c5b8f9e8b6 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Sun, 5 Nov 2023 12:00:28 +0000 Subject: Limit recursion, attempt 2 --- src/io/stream_reader.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/io/stream_reader.cpp') diff --git a/src/io/stream_reader.cpp b/src/io/stream_reader.cpp index f6f30a5b49..cf0dee38e8 100644 --- a/src/io/stream_reader.cpp +++ b/src/io/stream_reader.cpp @@ -27,6 +27,8 @@ namespace nbt namespace io { +constexpr int MAX_DEPTH = 1024; + std::pair> read_compound(std::istream& is, endian::endian e) { return stream_reader(is, e).read_compound(); @@ -74,8 +76,11 @@ std::pair> stream_reader::read_tag() std::unique_ptr stream_reader::read_payload(tag_type type) { + if (++depth > MAX_DEPTH) + throw input_error("Too deeply nested"); std::unique_ptr t = tag::create(type); t->read_payload(*this); + --depth; return t; } -- cgit 0.0.5-2-1-g0f52 From 3554a63406187b9dac5f72647644527f7fc3396b Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Mon, 6 Nov 2023 16:05:47 +0000 Subject: Small tweak Signed-off-by: TheKodeToad --- src/io/stream_reader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/io/stream_reader.cpp') diff --git a/src/io/stream_reader.cpp b/src/io/stream_reader.cpp index cf0dee38e8..28c1e1d89f 100644 --- a/src/io/stream_reader.cpp +++ b/src/io/stream_reader.cpp @@ -27,7 +27,7 @@ namespace nbt namespace io { -constexpr int MAX_DEPTH = 1024; +static constexpr int MAX_DEPTH = 1024; std::pair> read_compound(std::istream& is, endian::endian e) { -- cgit 0.0.5-2-1-g0f52