diff --git a/src/fileio.cpp b/src/fileio.cpp index 1458453958..e57c00a564 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -24,6 +24,7 @@ #include #include #endif +#include #include #include #include @@ -563,7 +564,16 @@ bool TarScanner::AddFile(const std::string &filename, size_t, [[maybe_unused]] c /* The size of the file, for some strange reason, this is stored as a string in octals. */ std::string size = ExtractString(th.size); - size_t skip = size.empty() ? 0 : std::stoul(size, nullptr, 8); + size_t skip = 0; + if (!size.empty()) { + StrTrimInPlace(size); + auto [_, err] = std::from_chars(size.data(), size.data() + size.size(), skip, 8); + if (err != std::errc()) { + Debug(misc, 0, "The file '{}' has an invalid size for '{}'", filename, name); + fclose(f); + return false; + } + } switch (th.typeflag) { case '\0':