Skip to content

Commit a863f1e

Browse files
committed
fds: sanity check for chunkSize, and validate size in decode_Frame()
More defense in depth: aligned_stream should prevent this from happening, but we can do some fairly lightweight sanity checks for general peace of mind. min chunk_size as 50 is arbitrary. There is surely an actual smallest number (it's at least "7", since the header is 6 bytes... but a wirehair size of 1 is bonkers), but for our purposes this is a safe "what do you think you're doing?" number.
1 parent 6a6b371 commit a863f1e

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/lib/fountain/fountain_decoder_sink.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class fountain_decoder_sink
5454
{
5555
public:
5656
fountain_decoder_sink(unsigned chunk_size, const std::function<std::string(const std::string&, const std::vector<uint8_t>&)>& on_store=nullptr)
57-
: _chunkSize(chunk_size)
57+
: _chunkSize(chunk_size < 50? 50 : chunk_size)
5858
, _onStore(on_store)
5959
{
6060
}
@@ -132,15 +132,18 @@ class fountain_decoder_sink
132132

133133
int64_t decode_frame(const char* data, unsigned size)
134134
{
135-
if (size < FountainMetadata::md_size)
135+
if ((size%_chunkSize) > 0)
136136
return -10;
137137

138+
if (size < FountainMetadata::md_size)
139+
return -11;
140+
138141
FountainMetadata md(data, size);
139142
if (!md.file_size())
140143
{
141144
/*std::cout << fmt::format("decode frame {} ... {},{},{},{}",
142145
md.file_size(), (unsigned)data[0], (unsigned)data[1], (unsigned)data[2], (unsigned)data[3]) << std::endl;*/
143-
return -11;
146+
return -12;
144147
}
145148

146149
// check if already done
@@ -151,7 +154,7 @@ class fountain_decoder_sink
151154
auto p = _streams.try_emplace(stream_slot(md), md.file_size(), _chunkSize);
152155
fountain_decoder_stream& s = p.first->second;
153156
if (s.data_size() != md.file_size())
154-
return -12;
157+
return -13;
155158

156159
bool finished = s.write(data, size);
157160
if (!finished)

0 commit comments

Comments
 (0)