mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:27:34 +00:00
Everywhere: Remove unintentional partial stream reads and writes
This commit is contained in:
parent
26516ee160
commit
ae51c1821c
44 changed files with 109 additions and 192 deletions
|
@ -225,10 +225,8 @@ ErrorOr<Bytes> DeflateDecompressor::read_some(Bytes bytes)
|
|||
if (block_type == 0b00) {
|
||||
m_input_stream->align_to_byte_boundary();
|
||||
|
||||
// FIXME: This should read the entire span.
|
||||
LittleEndian<u16> length, negated_length;
|
||||
TRY(m_input_stream->read_some(length.bytes()));
|
||||
TRY(m_input_stream->read_some(negated_length.bytes()));
|
||||
u16 length = TRY(m_input_stream->read_value<LittleEndian<u16>>());
|
||||
u16 negated_length = TRY(m_input_stream->read_value<LittleEndian<u16>>());
|
||||
|
||||
if ((length ^ 0xffff) != negated_length)
|
||||
return Error::from_string_literal("Calculated negated length does not equal stored negated length");
|
||||
|
|
|
@ -75,10 +75,8 @@ ErrorOr<Bytes> GzipDecompressor::read_some(Bytes bytes)
|
|||
current_member().m_nread += current_slice.size();
|
||||
|
||||
if (current_slice.size() < slice.size()) {
|
||||
// FIXME: This should read the entire span.
|
||||
LittleEndian<u32> crc32, input_size;
|
||||
TRY(m_input_stream->read_some(crc32.bytes()));
|
||||
TRY(m_input_stream->read_some(input_size.bytes()));
|
||||
u32 crc32 = TRY(m_input_stream->read_value<LittleEndian<u32>>());
|
||||
u32 input_size = TRY(m_input_stream->read_value<LittleEndian<u32>>());
|
||||
|
||||
if (crc32 != current_member().m_checksum.digest())
|
||||
return Error::from_string_literal("Stored CRC32 does not match the calculated CRC32 of the current member");
|
||||
|
@ -116,18 +114,16 @@ ErrorOr<Bytes> GzipDecompressor::read_some(Bytes bytes)
|
|||
return Error::from_string_literal("Header is not supported by implementation");
|
||||
|
||||
if (header.flags & Flags::FEXTRA) {
|
||||
// FIXME: This should read the entire span.
|
||||
LittleEndian<u16> subfield_id, length;
|
||||
TRY(m_input_stream->read_some(subfield_id.bytes()));
|
||||
TRY(m_input_stream->read_some(length.bytes()));
|
||||
u16 subfield_id = TRY(m_input_stream->read_value<LittleEndian<u16>>());
|
||||
u16 length = TRY(m_input_stream->read_value<LittleEndian<u16>>());
|
||||
TRY(m_input_stream->discard(length));
|
||||
(void)subfield_id;
|
||||
}
|
||||
|
||||
auto discard_string = [&]() -> ErrorOr<void> {
|
||||
char next_char;
|
||||
do {
|
||||
// FIXME: This should read the entire span.
|
||||
TRY(m_input_stream->read_some({ &next_char, sizeof(next_char) }));
|
||||
next_char = TRY(m_input_stream->read_value<char>());
|
||||
} while (next_char);
|
||||
|
||||
return {};
|
||||
|
@ -140,10 +136,9 @@ ErrorOr<Bytes> GzipDecompressor::read_some(Bytes bytes)
|
|||
TRY(discard_string());
|
||||
|
||||
if (header.flags & Flags::FHCRC) {
|
||||
// FIXME: This should read the entire span.
|
||||
LittleEndian<u16> crc16;
|
||||
TRY(m_input_stream->read_some(crc16.bytes()));
|
||||
u16 crc = TRY(m_input_stream->read_value<LittleEndian<u16>>());
|
||||
// FIXME: we should probably verify this instead of just assuming it matches
|
||||
(void)crc;
|
||||
}
|
||||
|
||||
m_current_member = TRY(Member::construct(header, *m_input_stream));
|
||||
|
|
|
@ -113,8 +113,7 @@ ErrorOr<void> ZlibCompressor::write_header(ZlibCompressionMethod compression_met
|
|||
|
||||
// FIXME: Support pre-defined dictionaries.
|
||||
|
||||
// FIXME: This should write the entire span.
|
||||
TRY(m_output_stream->write_some(header.as_u16.bytes()));
|
||||
TRY(m_output_stream->write_until_depleted(header.as_u16.bytes()));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
@ -155,8 +154,7 @@ ErrorOr<void> ZlibCompressor::finish()
|
|||
TRY(static_cast<DeflateCompressor*>(m_compressor.ptr())->final_flush());
|
||||
|
||||
NetworkOrdered<u32> adler_sum = m_adler32_checksum.digest();
|
||||
// FIXME: This should write the entire span.
|
||||
TRY(m_output_stream->write_some(adler_sum.bytes()));
|
||||
TRY(m_output_stream->write_value(adler_sum));
|
||||
|
||||
m_finished = true;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue