Commit graph

5473 commits

Author SHA1 Message Date
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 5f182746b6 LibCore: Stop logging that a Core::Socket has disconnected in receive()
This is perfectly normal and nothing we need to inform about.
2020-12-23 15:45:59 +01:00
Andreas Kling 75da835ffb LibDebug: Allow DWARF compilation unit header version <= 4
I think this is okay, the main thing to protect against is new versions
of the format that we don't know about yet.

This happens because an .S file compiled into libc.so has version 2
instead of version 4 like everything else.

Fixes #4491.
2020-12-23 00:53:27 +01:00
Érico Nogueira Rolim a8f0e489a4
LibCore: Rename identifiers that can clash with libc macros (#4127)
POSIX allows the default streams (stdin, stdout and stderr) to be
macros, which means that on such systems (musl libc is one) building
Lagom will fail due to the File::std*() names.

Also fix any files that use these identifiers.
2020-12-22 23:37:11 +01:00
AnotherTest 7c8d35600c Spreadsheet: Override visit_edges() and visit stored JS objects
...and don't let them leak out of their evaluation contexts.
Also keep the exceptions separate from the actual values.
This greatly reduces the number of assertions hit while entering random
data into a sheet.
2020-12-22 23:35:29 +01:00
Brendan Coles e8e8d3caf5 LibC: __generate_unique_filename(): Replace rand() with arc4random()
LibC stdlib `arc4random()` uses the `getrandom` system call which
uses `KernelRng::get_good_random_bytes`.

This ensures that filenames generated using functions such as
`mkstemp()` are suitably randomised and are no longer predictable.
2020-12-22 23:25:26 +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
Andreas Kling 780c64e1f0 LibELF: Fix ELF::Image::symbol_count() asserting on section-less ELF
If we have no sections, we also have no symbols, so just return 0.

Found by oss-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28683
2020-12-21 18:37:53 +01:00
Andreas Kling ab549cf942 LibGUI+TextEditor+HackStudio: Add GML syntax highlighter :^) 2020-12-21 18:26:18 +01:00
Andreas Kling 3d3084f088 LibGUi: Rework GML parser into a lexer+parser
This will make it easier to add GML syntax highlighting. :^)
2020-12-21 18:26:18 +01:00
Tom 5f51d85184 Kernel: Improve time keeping and dramatically reduce interrupt load
This implements a number of changes related to time:
* If a HPET is present, it is now used only as a system timer, unless
  the Local APIC timer is used (in which case the HPET timer will not
  trigger any interrupts at all).
* If a HPET is present, the current time can now be as accurate as the
  chip can be, independently from the system timer. We now query the
  HPET main counter for the current time in CPU #0's system timer
  interrupt, and use that as a base line. If a high precision time is
  queried, that base line is used in combination with quering the HPET
  timer directly, which should give a much more accurate time stamp at
  the expense of more overhead. For faster time stamps, the more coarse
  value based on the last interrupt will be returned. This also means
  that any missed interrupts should not cause the time to drift.
* The default system interrupt rate is reduced to about 250 per second.
* Fix calculation of Thread CPU usage by using the amount of ticks they
  used rather than the number of times a context switch happened.
* Implement CLOCK_REALTIME_COARSE and CLOCK_MONOTONIC_COARSE and use it
  for most cases where precise timestamps are not needed.
2020-12-21 18:26: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
Andreas Kling 09e069bc0b LibGUI: Soft tab expansion should be based on insertion column
We were using the line length as the column, which worked as long as
you were at the end of the line, but not so well otherwise. :^)
2020-12-21 09:26:31 +01:00
Brian Gianforcaro 4f86893927 LibC: Add SCNu64 and SCNd64 macros for stress-g port 2020-12-21 00:19:45 +01:00
Alex McGrath f1d7d864ae LibVT+Terminal: Add the option to disable the bell 2020-12-21 00:17:12 +01:00
William Marlow d16eabed06 LibGUI: Get executable file icons from PNGs stored in ELF sections.
If an ELF application contains sections called "serenity_icon_s"
or "serenity_icon_m" then parse these as PNG images and use them
for the 16x16 and 32x32 executable file icons respectively.

If the application is not an ELF binary, the sections do not
exist, the sections are not valid PNGs, or the file cannot be read
then the default application icon will be used.
2020-12-21 00:12:59 +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 6e0976d858 LibGUI: Make the GML parser a bit more fault-tolerant
It will now fail and whine in the debug log instead of asserting.
2020-12-20 14:30:40 +01:00
Andreas Kling 64ba41ea13 LibGUI: Make GUI::Label auto-sizing declarative
You can now set the "autosize" property on a GUI::Label and it will
automatically update its width preference to fit the text.
2020-12-20 12:36:32 +01:00
Andreas Kling de08e7b8c9 LibGUI: Rename ProgressBar property caption => text and expose to GML 2020-12-20 12:29:40 +01:00
Andreas Kling 48b0f4844b LibGUI: Add a couple more Widget registrations
Make it possible to instantiate BreadcrumbBar, ProgressBar and TreeView
from GML. :^)
2020-12-20 12:15:49 +01:00
Andreas Kling 822dc56ef3 LibGUI: Introduce GML - a simple GUI Markup Language :^)
This patch replaces the UI-from-JSON mechanism with a more
human-friendly DSL.

The current implementation simply converts the GML into a JSON object
that can be consumed by GUI::Widget::load_from_json(). The parser is
not very helpful if you make a mistake.

The language offers a very simple way to instantiate any registered
Core::Object class by simply saying @ClassName

@GUI::Label {
    text: "Hello friends!"
    tooltip: ":^)"
}

Layouts are Core::Objects and can be assigned to the "layout" property:

@GUI::Widget {
    layout: @GUI::VerticalBoxLayout {
        spacing: 2
        margins: [8, 8, 8, 8]
    }
}

And finally, child objects are simply nested within their parent:

@GUI::Widget {
    layout: @GUI::HorizontalBoxLayout {
    }
    @GUI::Button {
        text: "OK"
    }
    @GUI::Button {
        text: "Cancel"
    }
}

This feels a *lot* more pleasant to write than the JSON we had. The fact
that no new code was being written with the JSON mechanism was pretty
telling, so let's approach this with developer convenience in mind. :^)
2020-12-20 11:59:40 +01:00
Andreas Kling 18f1c49804 LibWeb: Don't leave "border" CSS property around after expansion
The "border" property is a shorthand that expands into multiple
longhand properties. We shouldn't leave it set in a StyleProperties
after expanding it.
2020-12-20 11:59:40 +01:00
Andreas Kling b30acdb4b7 LibTLS+Userland: Remove all uses of ByteBuffer::slice_view()
This was another way to get a non-owning ByteBuffer wrapper.
2020-12-19 18:29:13 +01:00
Andreas Kling d5600e966a LibTLS+LibCrypto: Remove all remaining uses of ByteBuffer::wrap() 2020-12-19 18:29:13 +01:00
Andreas Kling a8dbfc3398 LibCrypto: Yet more ByteBuffer::wrap() removal. Not much left now! 2020-12-19 18:29:13 +01:00
Andreas Kling 497f1fd472 LibWeb: Don't use ByteBuffer::wrap() when loading about: URLs
Let's just copy an empty string here to make ourselves a ByteBuffer.
2020-12-19 18:29:13 +01:00
Andreas Kling 48d74c5356 LibHTTP: Make HTTPRequest::from_raw_request() take a ReadonlyBytes
This allows us to get rid of some ByteBuffer::wrap() usage.
2020-12-19 18:29:13 +01:00
Andreas Kling e517505e35 LibTLS: Even more ByteBuffer -> Span conversion 2020-12-19 18:29:13 +01:00
Andreas Kling f82b0a78ef LibTLS+LibCrypto: More ByteBuffer -> Span conversion 2020-12-19 18:29:13 +01:00
Andreas Kling 8e20208dd6 LibTLS+LibCrypto: Replace a whole bunch of ByteBuffers with Spans 2020-12-19 18:29:13 +01:00
Andreas Kling 7c94856c12 LibELF+LibDebug: Remove use of ByteBuffer::wrap() 2020-12-19 13:14:00 +01:00
Andreas Kling 685d5f4e25 LibProtocol: Remove use of ByteBuffer::wrap() in protocol API 2020-12-19 13:09:02 +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
Andreas Kling 0e4ecca336 LibIPC: Remove use of ByteBuffer::wrap()
ByteBuffer::wrap() was useful before we had Span. Let's see if we can't
get rid of some more ByteBuffer wrapping.
2020-12-19 11:30:02 +01:00
AnotherTest 5d1425718e LibLine: Treat leftover data in buffer as a read event
Fixes #4328.
2020-12-18 19:20:37 +01:00
AnotherTest 5e6b9cbc91 LibLine: Be less lazy when moving prompt origin row
Fixes the issue where adding multiple lines in one refresh cycle would
break cursor positioning.
2020-12-18 19:20:37 +01:00
Brendan Coles 27a5c51f3f LibCore: UDPServer::bind: Replace bind failure assert() with perror() 2020-12-18 19:20:30 +01:00
Linus Groh fe88f46bc9 LibGUI: Don't assume main widget exists in Window::handle_resize_event()
Just like the other event handler functions, handle_resize_event()
shouldn't assume that the window has a main widget (which is being
resized in this case).

Fixes #4450.
2020-12-18 19:20:15 +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
Sahan Fernando 8dc0d9b7b7 LibGUI: Make autoformatting performed on InsertTextCommand visible to on_edit_action 2020-12-18 16:25:42 +01:00