summaryrefslogtreecommitdiffstats
path: root/src/lib/bootsplash.c
diff options
context:
space:
mode:
authorPatrick Georgi <patrick@coreboot.org>2023-10-06 20:19:15 +0200
committerFelix Held <felix-coreboot@felixheld.de>2023-12-13 16:17:34 +0000
commit1d029b40c9deca792ccc5820293d3bc8f8b8a2a4 (patch)
tree8936e4f3aeb4d8c0beed486bb3d7de62d858a373 /src/lib/bootsplash.c
parent54662610197d7304b48d8e85a5b13263db3357f2 (diff)
downloadcoreboot-1d029b40c9deca792ccc5820293d3bc8f8b8a2a4.tar.gz
coreboot-1d029b40c9deca792ccc5820293d3bc8f8b8a2a4.tar.bz2
coreboot-1d029b40c9deca792ccc5820293d3bc8f8b8a2a4.zip
lib/jpeg: Replace decoder with Wuffs' implementation
To quote its repo[0]: Wuffs is a memory-safe programming language (and a standard library written in that language) for Wrangling Untrusted File Formats Safely. Wrangling includes parsing, decoding and encoding. It compiles its library, written in its own language, to a C/C++ source file that can then be used independently without needing support for the language. That library is now imported to src/vendorcode/wuffs/. This change modifies our linters to ignore that directory because it's supposed to contain the wuffs compiler's result verbatim. Nigel Tao provided an initial wrapper around wuffs' jpeg decoder that implements our JPEG API. I further changed it a bit regarding data placement, dropped stuff from our API that wasn't ever used, or isn't used anymore, and generally made it fit coreboot a bit better. Features are Nigel's, bugs are mine. This commit also adapts our jpeg fuzz test to work with the modified API. After limiting it to deal only with approximately screen sized inputs, it fuzzed for 25 hours CPU time without a single hang or crash. This is a notable improvement over running the test with our old decoder which crashes within a minute. Finally, I tried the new parser with a pretty-much-random JPEG file I got from the internet, and it just showed it (once the resolution matched), which is also a notable improvement over the old decoder which is very particular about the subset of JPEG it supports. In terms of code size, a QEmu build's ramstage increases from 128060 bytes decompressed (64121 bytes after LZMA) to 172304 bytes decompressed (82734 bytes after LZMA). [0] https://github.com/google/wuffs Change-Id: If8fa7da69da1ad412f27c2c5e882393c7739bc82 Signed-off-by: Patrick Georgi <patrick@coreboot.org> Based-on-work-by: Nigel Tao <nigeltao@golang.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/78271 Reviewed-by: Paul Menzel <paulepanter@mailbox.org> Reviewed-by: Martin L Roth <gaumless@gmail.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src/lib/bootsplash.c')
-rw-r--r--src/lib/bootsplash.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/lib/bootsplash.c b/src/lib/bootsplash.c
index 3ab11aca6fad..0512770668d8 100644
--- a/src/lib/bootsplash.c
+++ b/src/lib/bootsplash.c
@@ -14,34 +14,40 @@ void set_bootsplash(unsigned char *framebuffer, unsigned int x_resolution,
unsigned int y_resolution, unsigned int bytes_per_line,
unsigned int fb_resolution)
{
+ if ((x_resolution > INT_MAX) || (y_resolution) > INT_MAX) {
+ printk(BIOS_ERR, "Display resolution way too large.\n");
+ return;
+ }
+ int xres = x_resolution, yres = y_resolution;
printk(BIOS_INFO, "Setting up bootsplash in %dx%d@%d\n", x_resolution, y_resolution,
fb_resolution);
- struct jpeg_decdata *decdata;
- unsigned char *jpeg = cbfs_map("bootsplash.jpg", NULL);
+ size_t filesize;
+ unsigned char *jpeg = cbfs_map("bootsplash.jpg", &filesize);
if (!jpeg) {
printk(BIOS_ERR, "Could not find bootsplash.jpg\n");
return;
}
- int image_width, image_height;
- jpeg_fetch_size(jpeg, &image_width, &image_height);
+ unsigned int image_width, image_height;
+ if (jpeg_fetch_size(jpeg, filesize, &image_width, &image_height) != 0) {
+ printk(BIOS_ERR, "Could not parse bootsplash.jpg\n");
+ return;
+ }
printk(BIOS_DEBUG, "Bootsplash image resolution: %dx%d\n", image_width, image_height);
- if (image_width > x_resolution || image_height > y_resolution) {
+ if (image_width > xres || image_height > yres) {
printk(BIOS_NOTICE, "Bootsplash image can't fit framebuffer.\n");
cbfs_unmap(jpeg);
return;
}
/* center image: */
- framebuffer += (y_resolution - image_height) / 2 * bytes_per_line +
- (x_resolution - image_width) / 2 * (fb_resolution / 8);
+ framebuffer += (yres - image_height) / 2 * bytes_per_line
+ + (xres - image_width) / 2 * (fb_resolution / 8);
- decdata = malloc(sizeof(*decdata));
- int ret = jpeg_decode(jpeg, framebuffer, image_width, image_height,
- bytes_per_line, fb_resolution, decdata);
- free(decdata);
+ int ret = jpeg_decode(jpeg, filesize, framebuffer, image_width, image_height,
+ bytes_per_line, fb_resolution);
cbfs_unmap(jpeg);
if (ret != 0) {
printk(BIOS_ERR, "Bootsplash could not be decoded. jpeg_decode returned %d.\n",