Commit graph

338 commits

Author SHA1 Message Date
Andreas Kling
92c073a9d1 LIbGUI+LibGfx: Paint focused push buttons with a heavier look
Draw a heavy shadow frame around focused push buttons for emphasis.
For now I've used the ThreedShadow2 color role as it feels dark enough.
2020-12-28 12:41:26 +01:00
Sahan Fernando
d780e2265d LibC: Fix some incorrect printf usages 2020-12-26 10:05:50 +01:00
Linus Groh
d8899ea65b WindowServer: Validate cursor type in SetWindowCursor message handler
Fixes #4536.
2020-12-25 23:07:06 +01:00
Andreas Kling
edf01803cd LibGfx: Make all image decoders reject image sizes above 16384 pixels
Let's just say no to shenanigans by capping images at 16384 pixels both
wide and tall. If a day comes in the future where we need to handle
images larger than this, we can deal with it then.
2020-12-25 00:19:06 +01:00
Andreas Kling
80ae407d73 LibGfx: Always compute the DIB mask shifts and sizes if needed
The pixel decoding logic later on assumes that if we have DIB masks,
we also have shifts and sizes, so we should make sure they are
always computed.

Found by oss-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28237
2020-12-23 20:16:53 +01:00
Andreas Kling
cd046fae44 LibGfx: Fail JPEG decode instead of asserting on bogus start-of-scan
Found by oss-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28628
2020-12-23 19:22:15 +01:00
Andreas Kling
0fc8561029 LibGfx: Catch integer overflows in PNG decoder and fail the decode
Found by oss-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28134&sort=reported&q=serenity
2020-12-23 19:04:12 +01:00
Andreas Kling
491a5f5e34 LibGfx: Avoid a ByteBuffer heap allocation in PNG filtering 2020-12-23 18:06:25 +01:00
Andreas Kling
068615fe5e LibGfx: Reject PNG files with invalid filter/interlace methods
Might as well reject these when parsing the IHDR chunk instead of
continuing to load something invalid.
2020-12-23 15:45:59 +01:00
Andreas Kling
531c3fe72e LibGfx: Fix OOB access in GIF deinterlacing
It was possible to go outside the interlacing row strid/offset arrays.
Just fail the decode if this is about to happen. I've added a FIXME
about rejecting such images earlier, since it's a bit sad to only do
this once we realize the pass index is about to overflow.

Found by oss-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28239
2020-12-22 10:09:41 +01:00
Lenny Maiorani
a95d230a3e LibGfx: Commonize functions in P*MLoader class implementations
Problem:
- Functions are duplicated in [PBM,PGM,PPM]Loader class
  implementations. They are functionally equivalent. This does not
  follow the DRY (Don't Repeat Yourself) principle.

Solution:
- Factor out the common functions into a separate file.
- Refactor common code to generic functions.
- Change `PPM_DEBUG` macro to be `PORTABLE_IMAGE_LOADER_DEBUG` to work
  with all the supported types. This requires adding the image type to
  the debug log messages for easier debugging.
2020-12-22 09:24:12 +01:00
Lenny Maiorani
58c52b155a LibGfx: Extraction of Streamer from P*MLoader
Problem:
- `Streamer` is the same in [PBM,PGM,PPM]Loader class implementations.

Solution:
- Extract it to its own header file to reduce maintenance burden.
- Implement `read` in terms of `read_bytes` to make the class "DRY".
- Decorate all functions with `constexpr`.
2020-12-21 09:58:27 +01:00
Lenny Maiorani
765936ebae
Everywhere: Switch from (void) to [[maybe_unused]] (#4473)
Problem:
- `(void)` simply casts the expression to void. This is understood to
  indicate that it is ignored, but this is really a compiler trick to
  get the compiler to not generate a warning.

Solution:
- Use the `[[maybe_unused]]` attribute to indicate the value is unused.

Note:
- Functions taking a `(void)` argument list have also been changed to
  `()` because this is not needed and shows up in the same grep
  command.
2020-12-21 00:09:48 +01:00
Andreas Kling
c7d0c2ee7a LibGfx: Teach all image decoders to fail on bitmap allocation failure
We don't need to wait for oss-fuzz to find this for us. :^)
2020-12-20 16:04:29 +01:00
Andreas Kling
3e0b913e44 LibGfx: Fail PNG decode if output bitmap can't be allocated
Otherwise we'll assert soon afterwards.

Found by oss-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28838
2020-12-20 15:24:50 +01:00
Andreas Kling
77515fead2 LibGfx: Remove use of ByteBuffer::wrap() in BMP decoder 2020-12-19 13:05:48 +01:00
Andreas Kling
8cf6b75dd9 LibGfx: Remove use of ByteBuffer::wrap() in PNG decoder 2020-12-19 12:00:35 +01:00
Nico Weber
573d5b7ff2 LibGfx: Give Size and Rect * and *= operators 2020-12-18 17:35:30 +01:00
Nico Weber
b67eed5b80 LibGfx: Fix type of scale factor in Point scale operators 2020-12-18 17:35:30 +01:00
Itamar
efe4da57df Loader: Stabilize loader & Use shared libraries everywhere :^)
The dynamic loader is now stable enough to be used everywhere in the
system - so this commit does just that.
No More .a Files, Long Live .so's!
2020-12-14 23:05:53 +01:00
Andreas Kling
96233bfc53 LibGfx: Draw checked buttons with a dithered base background
This looks just so right in the taskbar. :^)
2020-12-14 21:47:07 +01:00
AnotherTest
0918d8b1f8 LibGfx: Make fill_path() less bad at filling paths
This patchset fixes:
- Some parts of the path being skipped and not drawn (often horizontal)
- The filled shape moving around on an int grid depending on the winding
  number
- Winding number mess-up with four-way intersections
2020-12-12 20:10:04 +01:00
Sahan Fernando
fe3963f3d4 LibGfx: SIMD optimized alpha blending 2020-12-08 09:39:43 +01:00
Sahan Fernando
893adbb79c LibGfx: Simplify and refactor Gamma.h
Remove ACCURATE_GAMMA_ADJUSTMENT, since it makes the implementation
uglier, isn't guaranteed to make gamma adjustment accurate and is much
slower.  gamma_accurate_blend4 should either be always used or not
exist based on compilation flags, so there is no need to have it in
its own function. Finally, we should use AK/SIMD.h instead of defining
our own f32x4 type.
2020-12-08 09:39:43 +01:00
Andreas Kling
70c9cfddc5 LibGfx: Fix font x-height computation
Line indices start from the top, so the baseline is a higher number
than the mean line. :^)
2020-12-06 01:01:15 +01:00
Ben Wiederhake
ecb16f421d LibGfx: Handle OOM slightly better
When create_with_shared_buffer() is called in the next line, the
RefPtr::operator* asserts that the RefPtr is not null. That can happen when
we're low-ish on memory, and the image is huge.
2020-12-06 00:06:05 +01:00
Ben Wiederhake
aec8983819 LibGfx: Accept BMP RLE of 255 repeated bytes
Previously, in the case of RLE4, parsing took suspiciously long.
What happened was that 'pixel_count' was 255, and 'i' was incremented
by *two* in each iteration, so the for-loop continued until the
entire output buffer was full, and then rejected the RLE data
as bogus.

This little diff allows pixel_count to reach 256, be greater than
pixel_count, and thus terminate the loop in the intended way.
2020-12-02 22:51:05 +01:00
Ben Wiederhake
453c63fd04 LibGfx+BMP: Remove set_remaining, fix size check
The set_remaining method is inherently dangerous. It can be avoided easily here,
so let's do that.
2020-12-02 10:46:40 +01:00
Ben Wiederhake
36daeee34f LibGfx: Fix BMP mask detection off-by-one
Also, since the loops can be replaced by a little bit-twiddling,
call ctz() directly. This might be a bit faster, or it might not.
2020-12-02 10:46:40 +01:00
Ben Wiederhake
6be9b6349d LibGfx: Prevent potential heap-overflow in BMP non-RLE 2020-12-02 10:46:40 +01:00
Ben Wiederhake
461bdeda2b LibGfx: Fix heap-overflow in BMP RLE
The field previously named 'data_size' apparently was misunderstood.
2020-12-02 10:46:40 +01:00
Ben Wiederhake
d66b0683eb LibGfx: Distinguish between RGB data and file data
This was confusing and has hidden a bug, so let's change it.
2020-12-02 10:46:40 +01:00
Ben Wiederhake
9ff001c4d3 LibGfx: Avoid ByteBuffer assertions for huge bitmaps 2020-12-02 10:46:40 +01:00
Ben Wiederhake
d6c0776b45 LibGfx: Reject OS/2 BMP files with invalid bpp values 2020-12-02 10:46:40 +01:00
Ben Wiederhake
bd6d365166 LibGfx: Disallow RLE8 compression for 16bpp BMPs
Also, disallow similar silly combinations. Technically, we support *more* than
the definition seems to require.

For future reference:
https://archive.org/details/mac_Graphics_File_Formats_Second_Edition_1996/page/n607/mode/2up
Book page 580 (pdf page 608)
2020-12-02 10:46:40 +01:00
Ben Wiederhake
e3e2eecc33 LibGfx: Fix BMP compression checks
- OSv2 DIBs were not checked at all
- Regular Info DIBs had the compression checked after applying a 0xFF mask,
  which let many invalid compression values pass.
- There may still be a separate latent bug that causes mask_sizes and mask_shifts to be empty.
2020-12-02 10:46:40 +01:00
Ben Wiederhake
031814796e LibGfx: Recognize incomplete BMP colormaps 2020-12-02 10:46:40 +01:00
Ben Wiederhake
a4b207e04f LibGfx: Mark static method as static 2020-12-02 10:46:40 +01:00
Nico Weber
eef30bb05e LibGfx: Add some validation to BMPLoader
These changes fixed various asserts when I ran the fuzzer locally a
while ago.
2020-12-01 16:48:22 +01:00
Ben Wiederhake
f82b2948cf Meta: Fix BMP_DEBUG, and always build on CI 2020-12-01 11:06:53 +01:00
AnotherTest
b2d698472b LibGfx: Add a 'Point::absolute_relative_distance_to(Point)'
This is significantly more elegant than subtracting the points and
constructing another point from the abs() of their individual
components.
2020-11-30 12:07:45 +01:00
devashish
2a332d8669 JPGLoader: Use HashMap to store huffman tables
This patch rids us of the ugly hack that we had to go through while
handling table redefinitons.
2020-11-30 11:37:51 +01:00
Nico Weber
34c5478f31 LibGfx: Validate bit depths, and don't assert on invalid color type
The PNG spec says that each color type only allows certain bit depths,
so add explicit checks for that.
2020-11-29 21:28:44 +01:00
Nico Weber
fe999d6281 LibGfx: Make PNGLoader not assert on images with missing chunks
Before this, images without IHDR, or palettized images with no or
too small PLTE would lead to asserts. Found by running FuzzPNGLoader
locally.
2020-11-29 21:28:44 +01:00
Nico Weber
7db765bb73 LibGfx: Put debug output in PNGLoader behind PNG_DEBUG 2020-11-29 21:28:44 +01:00
Luke
d7455018eb LibGfx: gamma_to_linear4 is not a valid constexpr on clang 10 and below
This is a hack which can be removed once GitHub Actions changes the
default version to clang 11.

This is apparently sometime in mid-December.

Note, clang-11 is not currently available on Ubuntu 20.04. However,
GitHub Actions uses 20.04, which probably means clang-11 will
become available around that time for all 20.04 users.
2020-11-29 20:22:56 +01:00
Nico Weber
1f22a59f9d LibGfx: Don't assert on files ending right before lzw_min_code_size
Not yet found by oss-fuzz, but I hit it a while ago when running
FuzzGIFLoader locally.
2020-11-29 20:21:30 +01:00
Nico Weber
86cec77eb5 LibGfx: skip zero-width frames
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=27913
and https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=27873
2020-11-29 20:21:30 +01:00
devashish
4d7ba50dc7 JPGLoader: Move bogus JPEGs to a different directory 2020-11-29 16:22:04 +01:00
devashish
f107c70652 JPGLoader: Use HashMap instead of Vector for storing components
The JPEG spec allows component IDs to be chosen arbitrarily from the
interval [0, 255]. Storing components in a vector corrupts the decoder
when component IDs are not in the range 0-3. Normally, encoders don't
use IDs outside of that range because JPEG doesn't support more than
4 channels. But since there is a chance that a spec compliant JPEG
would have component IDs outside of [0-3], we should consider replacing
the vector, which enforces serial component access based on component
IDs, with a HashMap<u8, ComponentSpec>.
2020-11-29 16:22:04 +01:00