Commit graph

469 commits

Author SHA1 Message Date
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
Nico Weber
ec4c2f971b Lagom: Make BMP fuzzer look like the other image loader fuzzers 2020-11-26 09:59:46 +01:00
BenJilks
216385084b LibGfx: Add BMPWriter
This utility allows you to create a BMP file from a bitmap
2020-11-22 16:07:00 +01:00
Nico Weber
700fe315cf LibGfx: Make some GIFLoader magic numbers a bit less magic
No behavior change.
2020-11-20 21:17:58 +01:00
Nico Weber
967c82c1be LibGfx: Put GIFLoader logging behind GIF_DEBUG 2020-11-20 21:17:58 +01:00
Nico Weber
ebfc21509a LibGfx: De-constexpr Gamma.h
__builtin_sqrtf() isn't constexpr in clang.
2020-11-20 21:17:58 +01:00
Sahan Fernando
1b9a85e4f1 LibGfx: Use gamma-corrected interpolation for color gradients
Switch over to gamma-aware interpolation. This causes color gradients
to not look so dark in the middle. SIMD optimized code is provided for
sse1 enabled builds.

Fixes #1342.
2020-11-19 21:24:20 +01:00
Nico Weber
7042490e41 LibGfx: Bounds check component indices before using them in JPGLoader
With this, I don't see any crashes in 10 min of fuzzing (but still
get OOMs).
2020-11-19 21:21:45 +01:00
Nico Weber
a8318b15a7 LibGfx: Check for read failures after every read in jpg loader
This doesn't fix all the issues found by the fuzzer, but it fixes
many of them. When running this

    Meta/Lagom/Fuzzers/FuzzJPGLoader -jobs=24 -workers=24 \
        ../Base/res/html/misc/jpgsuite_files/

for 10 minutes on my machine, the fuzzer foudn 2 crashers, but after
this change it finds just ... 2. But with different stacks!

This just fixes ASSERT()s, so it's not security critical, but
ASSERT()s still crash the programs decoding JPGs, and crashing
less is nice even if it's not a security concern.
2020-11-19 21:21:45 +01:00
Nico Weber
129a0666cb LibGfx: Put remaining jpg logging behind JPG_DEBUG
...except for one happy-case log line which is removed wholesale.
2020-11-19 21:21:45 +01:00
Nico Weber
3749e167b4 LibGfx: Move JPGLoader to a more regular JPG_DEBUG macro as used elsewhere 2020-11-19 21:21:45 +01:00
Nico Weber
9ea709e1f3 LibGfx: Put PPM logs behind (default-off) PPM_DEBUG 2020-11-19 14:04:35 +01:00
Andreas Kling
9ffdb71111 LibGfx: Don't leak malloc memory in cloned fonts
Fixes #4083.
2020-11-15 11:35:07 +01:00
Linus Groh
5b68ea8dde LibGfx: Make Bitmap path handling case insensitive
Bitmap::is_path_a_supported_image_format() and Bitmap::load_from_file()
now check the file extension with CaseSensitivity::CaseInsensitive.

This fixes a couple of inconsistencies, for example would
FileSystemModel::icon_for() recognize image files uppercase extensions
but couldn't create thumbnails for them (any attempt to create a bitmap
from such files would fail).
2020-11-14 10:11:26 +01:00
Andreas Kling
69518bd178 LibGfx: Fail PPM decode if there's not enough pixel data in the input
Fixes #3820.
2020-11-13 12:01:32 +01:00
Andreas Kling
f234b8c129 LibGfx: Add missing stream error handling in GIF frame descriptor parse
If we try to read a sentinel byte but the stream is fresh out of data,
we have to take care of the stream error and bail out right away, or
we'll hit an assertion when exiting the function soon after.

Fixes #3486.
2020-11-13 12:01:29 +01:00
Andreas Kling
c0aa455f76 LibGfx: Refuse to decode PNG images with geometry outside i32 bounds
Just fail the decode immediately when encountering an IHDR chunk with
width and/or height larger than the maximum i32 value.

Fixes #3818.
Fixes #3819.
2020-11-13 12:01:25 +01:00
AnotherTest
705ad670f3 LibGfx: Add methods to serialise and deserialise a Bitmap
Unlike `to_shared_buffer()` and co, these methods do *not* require extra
metadata about the bitmap.
2020-11-08 21:46:13 +01:00
Peter Nelson
e23daa90a3 LibGfx: remove debug printfs from GIFLoader 2020-11-08 21:40:47 +01:00
Peter Nelson
fa57083552 LibGfx: gracefully handle GIFs with frame decode errors
GIFLoader now tracks the state of errors during the decoding process
and will fall back to displaying the first frame of the GIF if any of
the subsequent frames fail to decode.
2020-11-08 21:40:47 +01:00