Commit graph

3360 commits

Author SHA1 Message Date
Tim Schumacher
197331c922 AK: Reject BitStream reads beyond EOF by default
The only exception to this is the lossless WebP decoder, which
legitimately relies on this behavior, even upstream.
2023-12-01 12:48:18 +01:00
Tim Schumacher
cb03d3d78f AK: Allow rejecting BitStream reads beyond EOF 2023-12-01 12:48:18 +01:00
Tim Schumacher
de49413bdf AK: Don't slice off the first byte of a BitStream read 2023-12-01 12:48:18 +01:00
Lucas CHOLLET
aaf54f8cf8 AK: Allow Optional<T&> to be constructed by OptionalNone()
This is an extension of cc0b970d but for the reference-handling
specialization of Optional.

This basically allow us to write code like:
```cpp
Optional<u8&> opt;
opt = OptionalNone{};
```
2023-11-29 02:19:41 +03:30
Shannon Booth
6b32a1f18f AK+LibUnicode: Expose TrailingCodePointTransformation in to_titlecase
Relocating the definition of this enum from LibUnicode to AK.
2023-11-28 17:15:27 -05:00
Timothy Flynn
6aa334767f AK: Ensure assigned-to Strings are dereferenced if needed
If we assign to an existing non-short string, we must dereference its
StringData object to prevent leaking that data.
2023-11-28 16:38:18 +01:00
Michiel Visser
51fe8f820f AK: Fix compile error when using div_mod_internal<513, 256, true> 2023-11-27 09:43:07 +03:30
Dan Klishch
80d1c93edf AK+Applications: Return value from JsonObject::get_double more often
Previously, we were returning an empty optional if key contained a
numerical value which was not stored as double. Stop doing that and
rename the method to signify the change in the behavior.

Apparently, this fixes bug in an InspectorWidget in Ladybird on
Serenity: it showed 0 for element's boxes with integer sizes.
2023-11-25 11:02:17 +01:00
Andreas Kling
a6106ca221 AK: Use __builtin_offsetof() + -Wno-invalid-offsetof to silence ASAN
ASAN was crying way too much when running the LibJS JIT since the old
OFFSET_OF implementation was too wild for its liking.

By turning off the invalid-offsetof warnings, we can use the offsetof
builtin instead. However, I'm leaving this as a wrapper macro, since
we may still want to do something different for other compilers.
2023-11-24 12:49:15 +01:00
timmot
da3cfd5bbc AK+LibWeb: Make clamp_to_int generic over all integrals 2023-11-24 08:42:18 +01:00
Andrew Kaster
bbdf766fb0 AK: Add helpers to convert arbitrary Spans to {Readonly}Bytes
The streams and other common APIs require byte spans to operate on
arbitrary data. This is less than helpful when wanting to serialize
spans of other data types, such as from an Array or Vector of u32s.
2023-11-24 08:41:38 +01:00
Martin Janiczek
58d0577a02 AK: Fix bugs in Complex += -= + - * / operators
There were two issues:

1) the C+=R and C-=R operators expected arithmetic types to have .real()

2) the R+C, R-C, R*C and R/C operators applied the operation in wrong
   order (did C+R, C-R, C*R and C/R instead). This wouldn't matter for
   + and * which are commutative, but is incorrect for - and /.
2023-11-23 19:54:39 -05:00
MacDue
da00a5cdb5 AK: Add is_owned() method to MaybeOwned 2023-11-18 19:32:31 +01:00
Timothy Flynn
2c1bbf5a99 AK+LibIDL: Put IDL dbgln statement behind a debug flag
This is a bit spammy now that we are performing some overload resolution
at build time. The fallback to an interface has generally worked fine on
the types it warns about (BufferSource, Module, etc.) so let's not warn
about it for every build.
2023-11-15 23:42:53 +01:00
Dan Klishch
c0ffff7e88 AK: Ban JsonValue from the kernel and remove ifdef guards
JsonValue can store JsonObject which uses DS for keys, so it is not safe
to use it in the kernel even with the double/String guards.
2023-11-14 10:06:54 +01:00
Lucas CHOLLET
86ee7d219e LibCompress/LZW: Use its own debug flag
The file still used the `GIF_DEBUG` flag from when it was a part of the
GIF decoder. Let's give `LZWDecoder` its own flag.
2023-11-12 13:56:27 +01:00
Lucas CHOLLET
6f059c9d60 AK: Add the InputBitStream concept
This will allow users to abstract away the endianness of the stream they
are using.
2023-11-12 13:56:27 +01:00
Michiel Visser
be68f747b6 AK: Add shorthands for u384, u768, and u1536 2023-11-11 14:40:10 +03:30
Nico Weber
bda162fc0d AK: Add Span::reverse()
It works like Vector::reverse().
2023-11-09 16:06:25 +01:00
Tim Schumacher
e9dda2a5f8 AK: Provide a default set of Traits for const types 2023-11-09 10:05:51 -05:00
Tim Schumacher
a2f60911fe AK: Rename GenericTraits to DefaultTraits
This feels like a more fitting name for something that provides the
default values for Traits.
2023-11-09 10:05:51 -05:00
Andreas Kling
55e467c359 LibJS/JIT: Add fast path for cached PutById 2023-11-09 16:02:14 +01:00
Timothy Flynn
e576bf975c AK: Define traits for the const-variant of BigEndian and LittleEndian 2023-11-08 22:26:36 +00:00
Timothy Flynn
370ea9441c AK: Define an alias for Utf16View's iterator type
Utf8View and Utf32View do so already. This allows using these views more
readily in generic code.
2023-11-08 12:54:26 -05:00
Lucas CHOLLET
b00476abac AK: Use an enum to specify the open mode instead of a bool
Let's replace this bool with an `enum class` in order to enhance
readability. This is done by repurposing `MappedFile`'s `OpenMode` into
a shared `enum` simply called `Mode`.
2023-11-08 18:19:34 +01:00
Sam Atkins
1519290989 AK: Cast pointer in FixedMemoryStream::read_in_place(count)
I didn't notice this before because I only ever called it with u8. Oops!
2023-11-08 09:34:09 +01:00
Timothy Flynn
2437064820 AK: Define compound subtraction operator for UnixDateTime 2023-11-08 09:28:17 +01:00
Shannon Booth
8c8ea86729 AK: Add FlyString::starts_with_bytes and FlyString::ends_with_bytes
Mirroring the API for String
2023-11-07 11:33:41 +01:00
Andreas Kling
0bbf230e4f AK: Expose the memory offset of Vector's outline buffer pointer 2023-11-07 11:33:04 +01:00
Andreas Kling
bdce36dddb AK: Expose memory offset of Optional's internal fields 2023-11-07 11:33:04 +01:00
Andreas Kling
af5fd99ff4 AK: Add OFFSET_OF macro that works on class member fields 2023-11-07 11:33:04 +01:00
Lucas CHOLLET
75caccafa4 LibGfx: Add a TIFF loader 2023-11-06 12:29:30 -07:00
Tim Ledbetter
2a1fc96650 AK: Avoid unnecessary String allocations for URL username and password
Previously, `URLParser` was constructing a new String for every
character of the URL's username and password. This change improves
performance by eliminating those unnecessary String allocations.

A URL with a 100,000 character password can now be parsed in ~30ms vs
~8 seconds previously on my machine.
2023-11-06 09:19:12 +01:00
Andreas Kling
0902f552a3 AK: Bring some missing DeprecatedString API over to String
Specifically, case sensitivity parameters for starts/ends with,
and the equals_ignoring_ascii_case() helper.
2023-11-04 21:28:30 +01:00
Dan Klishch
b65d281bbb AK: Add GenericLexer::{consume_decimal_integer,peek_string} 2023-11-04 18:06:30 +01:00
Hendiadyoin1
e02a4f5181 AK: Bring JsonParser's string consumption closer to the ECMA 404 spec
I added some spec comments, and implementation notices, this should not
change behavior in a significant way.

The previous code was quite unwieldy and repetitive.
The long `if(next_is('X'))` chain is now a smaller `switch`.
I also reinstated the fast path for long sequences of literal
characters, which was broken in 0aad21fff2
2023-11-01 17:28:19 -06:00
Timothy Flynn
f630a5ca71 AK+LibJS: Remove error-prone JsonValue constructor
Consider the following:

    JsonValue value { JsonValue::Type::Object };
    value.as_object().set("foo"sv, "bar"sv);

The JsonValue(Type) constructor does not initialize the underlying union
that stores its value. Thus JsonValue::as_object() will A) refer to an
uninitialized union member, B) deference that member.

This constructor only has 2 users, both of which initialize the type to
Type::Null. Rather than implementing unused functionality here, replace
those uses with the default JsonValue constructor, and remove the faulty
constructor.
2023-11-01 11:15:26 -04:00
Ali Mohammad Pur
7976e1852c AK: Ensure unions with bitfield structs actually have correct sizes
The fun pattern of `union { struct { u32 a : 1; u64 b : 7; }; u8 x; }`
produces complete garbage on windows, this commit fixes the two
instances of those that exist in AK.
This commit also makes sure that the generated unions have the correct
size (whereas FloatExtractor<f32> previously did not!) by adding some
nice static_asserts.
2023-11-01 09:10:38 +03:30
Ali Mohammad Pur
bec1c1fff7 AK: Explicitly instantiate FormatBuilder::put_f32_or_f64<{f32,f64}>
The default visibility of this function's implicit instantiation was
somehow different on macOS, this fixes that and doesn't affect anything
else.
2023-10-31 11:31:17 +03:30
Ali Mohammad Pur
78c04cb8b2 AK+LibPDF: Make Format print floats in a roundtrip-safe way by default
Previously we assumed a default precision of 6, which made the printed
values quite odd in some cases.
This commit changes that default to print them with just enough
precision to produce the exact same float when roundtripped.

This commit adds some new tests that assert exact format outputs, which
have to be modified if we decide to change the default behaviour.
2023-10-31 09:12:35 +03:30
Gurkirat Singh
f1b79e0cd3 AK: Implement slugify function for URL slug generation
The slugify function is used to convert input into URL-friendly slugs.
It processes each character in the input, keeping ascii alpha characters
after lowercase and replacing non-alphanum characters with the glue
character or a space if multiple spaces are encountered consecutively.
The resulting string is trimmed of leading and trailing whitespace, and
any internal whitespace is replaced with the glue character.

It is currently used in LibMarkdown headings generation code.
2023-10-30 10:39:59 +00:00
Ali Mohammad Pur
cafe60d713 AK: Disable assertion output colors on windows 2023-10-29 07:40:35 +01:00
Tim Ledbetter
e4715aa82a AK: Use correct type when calculating integral exp2()
Previously, integral `exp2()` would produce the incorrect result for
exponents above 31.
2023-10-27 21:59:44 -04:00
Idan Horowitz
702dd0ca55 AK: Use array element count instead of memory size in backtrace call
The backtrace execinfo API takes the number of addresses the result
buffer can hold instead of its size, for some reason. Previously
backtraces larger than 256 frames deep would write past the end of the
result buffer.
2023-10-27 16:06:35 -04:00
Ali Mohammad Pur
072c4eeb50 AK: Make SipHash not depend on size_t bit length
That breaks on 32-bit systems, this commit makes it so they're always
stored in a u64 as the code requires.
2023-10-27 05:57:18 +03:30
Shannon Booth
3748f1d290 AK: Check for overflow parsing IPv4 number in URL
Fixes OSS fuzz issue:
https://oss-fuzz.com/download?testcase_id=6045676088459264
2023-10-26 11:11:41 +02:00
Shannon Booth
453dd0cf44 AK: Properly implement steps for shortening a URLs path
Instead of implementing this inline, put it into a function. Use this
new function to correctly implement shortening paths for some places
where this logic was previously missing.

Before these changes, the pathname for the included test was incorrectly
being set to '/' as we were not considering the windows drive letter.
2023-10-26 11:11:41 +02:00
Shannon Booth
bfdf7779ce AK: Correctly set host when parsing URL with a base file:// host
We were completely missing this spec step here. Also leave a FIXME for
the pre-existing implementation of this step, as this doesn't match the
spec.
2023-10-26 11:11:41 +02:00
Shannon Booth
ef27750982 AK: Port URL m_paths to String 2023-10-26 11:11:41 +02:00
Shannon Booth
e9670862a0 AK: Simplify "cannot have a username/password/port"
This is an editorial change in the URL spec, see:

https://github.com/whatwg/url/commit/f78785
2023-10-26 11:11:41 +02:00