From 5d0434d13d0145a110c0c93e59edfd7d062f8531 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sun, 24 Apr 2016 16:21:44 +0200 Subject: Fix OOM bug: UTXO entries with invalid script length --- src/streams.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/streams.h') diff --git a/src/streams.h b/src/streams.h index a50fe4e859..ed14f3f412 100644 --- a/src/streams.h +++ b/src/streams.h @@ -406,6 +406,20 @@ public: return (*this); } + CAutoFile& ignore(size_t nSize) + { + if (!file) + throw std::ios_base::failure("CAutoFile::ignore: file handle is NULL"); + unsigned char data[4096]; + while (nSize > 0) { + size_t nNow = std::min(nSize, sizeof(data)); + if (fread(data, 1, nNow, file) != nNow) + throw std::ios_base::failure(feof(file) ? "CAutoFile::ignore: end of file" : "CAutoFile::read: fread failed"); + nSize -= nNow; + } + return (*this); + } + CAutoFile& write(const char* pch, size_t nSize) { if (!file) -- cgit v1.2.3