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`.
This commit is contained in:
devgianlu 2025-03-01 19:26:17 +01:00 committed by Jelle Raaijmakers
parent e02521911a
commit 033ba43faf
Notes: github-actions[bot] 2025-03-19 12:47:55 +00:00
3 changed files with 8 additions and 12 deletions

View file

@ -115,9 +115,8 @@ WebIDL::ExceptionOr<void> CompressionStream::compress_and_enqueue_chunk(JS::Valu
// 2. Let buffer be the result of compressing chunk with cs's format and context.
auto maybe_buffer = [&]() -> ErrorOr<ByteBuffer> {
if (auto buffer = WebIDL::underlying_buffer_source(chunk.as_object()))
return compress(buffer->buffer(), Finish::No);
return ByteBuffer {};
auto chunk_buffer = TRY(WebIDL::get_buffer_source_copy(chunk.as_object()));
return compress(move(chunk_buffer), Finish::No);
}();
if (maybe_buffer.is_error())
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, MUST(String::formatted("Unable to compress chunk: {}", maybe_buffer.error())) };

View file

@ -117,11 +117,8 @@ WebIDL::ExceptionOr<void> DecompressionStream::decompress_and_enqueue_chunk(JS::
// 2. Let buffer be the result of decompressing chunk with ds's format and context. If this results in an error,
// then throw a TypeError.
auto maybe_buffer = [&]() -> ErrorOr<ByteBuffer> {
auto chunk_buffer = WebIDL::underlying_buffer_source(chunk.as_object());
if (!chunk_buffer)
return ByteBuffer {};
TRY(m_input_stream->write_until_depleted(chunk_buffer->buffer()));
auto chunk_buffer = TRY(WebIDL::get_buffer_source_copy(chunk.as_object()));
TRY(m_input_stream->write_until_depleted(move(chunk_buffer)));
auto decompressed = TRY(ByteBuffer::create_uninitialized(4096));
auto size = TRY(m_decompressor.visit([&](auto const& decompressor) -> ErrorOr<size_t> {

View file

@ -2,7 +2,7 @@ Harness status: OK
Found 3 tests
3 Fail
Fail deflate compression with large flush output
Fail gzip compression with large flush output
Fail deflate-raw compression with large flush output
3 Pass
Pass deflate compression with large flush output
Pass gzip compression with large flush output
Pass deflate-raw compression with large flush output