RequestServer: Do not pack the disk cache header and footer structures

This is causing misaligned reads with Address Sanitizer enabled. We
could maintain the packed attribute, and deal with alignment - but we
ended up not actually needing these to be packed anyways. The only thing
we need to know is the serialized size of the header, which we can just
determine differently.
This commit is contained in:
Timothy Flynn 2025-11-18 15:24:24 -05:00 committed by Jelle Raaijmakers
parent 71f9c77ee1
commit 0020af37cd
Notes: github-actions[bot] 2025-11-20 08:35:56 +00:00
2 changed files with 5 additions and 3 deletions

View file

@ -194,12 +194,14 @@ ErrorOr<NonnullOwnPtr<CacheEntryReader>> CacheEntryReader::create(DiskCache& dis
auto fd = file->fd();
CacheHeader cache_header;
size_t cache_header_size { 0 };
String url;
Optional<String> reason_phrase;
auto result = [&]() -> ErrorOr<void> {
cache_header = TRY(file->read_value<CacheHeader>());
cache_header_size = TRY(file->tell());
if (cache_header.magic != CacheHeader::CACHE_MAGIC)
return Error::from_string_literal("Magic value mismatch");
@ -224,7 +226,7 @@ ErrorOr<NonnullOwnPtr<CacheEntryReader>> CacheEntryReader::create(DiskCache& dis
return result.release_error();
}
auto data_offset = sizeof(CacheHeader) + cache_header.url_size + cache_header.reason_phrase_size;
auto data_offset = cache_header_size + cache_header.url_size + cache_header.reason_phrase_size;
return adopt_own(*new CacheEntryReader { disk_cache, index, cache_key, move(url), move(path), move(file), fd, cache_header, move(reason_phrase), move(response_headers), data_offset, data_size });
}

View file

@ -18,7 +18,7 @@
namespace RequestServer {
struct [[gnu::packed]] CacheHeader {
struct CacheHeader {
static ErrorOr<CacheHeader> read_from_stream(Stream&);
ErrorOr<void> write_to_stream(Stream&) const;
@ -35,7 +35,7 @@ struct [[gnu::packed]] CacheHeader {
u32 reason_phrase_hash { 0 };
};
struct [[gnu::packed]] CacheFooter {
struct CacheFooter {
static ErrorOr<CacheFooter> read_from_stream(Stream&);
ErrorOr<void> write_to_stream(Stream&) const;