From 9672b125531f4d3eda3d8483cf1d63d71ebc9875 Mon Sep 17 00:00:00 2001 From: Tor Brede Vekterli Date: Thu, 5 May 2022 10:54:35 +0000 Subject: Early return from asciistream file read if file is empty Avoids a transitive vespalib::string append with nullptr buffer and zero length, which in turn ends up passing nullptr to memmove, which is undefined. --- vespalib/src/vespa/vespalib/stllike/asciistream.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'vespalib') diff --git a/vespalib/src/vespa/vespalib/stllike/asciistream.cpp b/vespalib/src/vespa/vespalib/stllike/asciistream.cpp index eb127c7051a..6b673363d2d 100644 --- a/vespalib/src/vespa/vespalib/stllike/asciistream.cpp +++ b/vespalib/src/vespa/vespalib/stllike/asciistream.cpp @@ -628,6 +628,9 @@ asciistream::createFromFile(stringref fileName) if (sz < 0) { throw IoException("Failed getting size of file " + fileName + " : Error=" + file.getLastErrorString(), IoException::UNSPECIFIED, VESPA_STRLOC); } + if (sz == 0) { + return is; + } alloc::Alloc buf = alloc::Alloc::alloc(sz); ssize_t actual = file.Read(buf.get(), sz); if (actual != sz) { -- cgit v1.2.3