Skip to content

Commit 033ba43

Browse files
devgianlugmta
authored andcommitted
LibWeb: Use get_buffer_source_copy for getting the actual byte buffer
`WebIDL::underlying_buffer_source` gets the underlying buffer source which is not resized according to, for example, `subarray`.
1 parent e025219 commit 033ba43

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

Libraries/LibWeb/Compression/CompressionStream.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,8 @@ WebIDL::ExceptionOr<void> CompressionStream::compress_and_enqueue_chunk(JS::Valu
115115

116116
// 2. Let buffer be the result of compressing chunk with cs's format and context.
117117
auto maybe_buffer = [&]() -> ErrorOr<ByteBuffer> {
118-
if (auto buffer = WebIDL::underlying_buffer_source(chunk.as_object()))
119-
return compress(buffer->buffer(), Finish::No);
120-
return ByteBuffer {};
118+
auto chunk_buffer = TRY(WebIDL::get_buffer_source_copy(chunk.as_object()));
119+
return compress(move(chunk_buffer), Finish::No);
121120
}();
122121
if (maybe_buffer.is_error())
123122
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, MUST(String::formatted("Unable to compress chunk: {}", maybe_buffer.error())) };

Libraries/LibWeb/Compression/DecompressionStream.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,8 @@ WebIDL::ExceptionOr<void> DecompressionStream::decompress_and_enqueue_chunk(JS::
117117
// 2. Let buffer be the result of decompressing chunk with ds's format and context. If this results in an error,
118118
// then throw a TypeError.
119119
auto maybe_buffer = [&]() -> ErrorOr<ByteBuffer> {
120-
auto chunk_buffer = WebIDL::underlying_buffer_source(chunk.as_object());
121-
if (!chunk_buffer)
122-
return ByteBuffer {};
123-
124-
TRY(m_input_stream->write_until_depleted(chunk_buffer->buffer()));
120+
auto chunk_buffer = TRY(WebIDL::get_buffer_source_copy(chunk.as_object()));
121+
TRY(m_input_stream->write_until_depleted(move(chunk_buffer)));
125122

126123
auto decompressed = TRY(ByteBuffer::create_uninitialized(4096));
127124
auto size = TRY(m_decompressor.visit([&](auto const& decompressor) -> ErrorOr<size_t> {

Tests/LibWeb/Text/expected/wpt-import/compression/compression-large-flush-output.any.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Harness status: OK
22

33
Found 3 tests
44

5-
3 Fail
6-
Fail deflate compression with large flush output
7-
Fail gzip compression with large flush output
8-
Fail deflate-raw compression with large flush output
5+
3 Pass
6+
Pass deflate compression with large flush output
7+
Pass gzip compression with large flush output
8+
Pass deflate-raw compression with large flush output

0 commit comments

Comments
 (0)