fix dangerous unchecked file stream read

This commit is contained in:
Green Sky 2024-07-22 19:49:02 +02:00
parent 54ace9d0b2
commit 16cb755191
No known key found for this signature in database

View File

@ -8,6 +8,7 @@
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <cstring> #include <cstring>
#include <cassert>
struct File2RWMapped : public File2I { struct File2RWMapped : public File2I {
mio::ummap_sink _file_map; mio::ummap_sink _file_map;
@ -64,8 +65,14 @@ struct File2RWMapped : public File2I {
} }
ByteSpanWithOwnership read(uint64_t size, int64_t pos = -1) override { ByteSpanWithOwnership read(uint64_t size, int64_t pos = -1) override {
// TODO: support streaming read
if (pos < 0) {
assert(false && "streaming not implemented");
return ByteSpan{};
}
if (pos+size > _file_size) { if (pos+size > _file_size) {
//assert(false && "read past end"); assert(false && "read past end");
return ByteSpan{}; return ByteSpan{};
} }