Skip to contentSkip to conversation

tools: bmp_logo: correctly interpret BMP files with larger headers

PATCH In review Jon Smith 2 participants 2 messages Oct 5, 2017 – Oct 17, 2017

lore
Share & tools
lore

Jon Smith

author
#0 lore raw

PATCH 1/1 tools: bmp_logo: correctly interpret BMP files with larger headers

All BMP files were being treated as though they had a 40 byte header. There are several BMP header formats consisting of additional data. This was causing some of the header to be read as color information, skewing the color palette.

---

 tools/bmp_logo.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
tools/bmp_logo.c +8 -3
index 2247adcc82..55f833fb9b 100644
@@ -76,7 +76,7 @@ int main (int argc, char *argv[])
 	FILE	*fp;
 	bitmap_t bmp;
 	bitmap_t *b = &bmp;
-	uint16_t data_offset, n_colors;
+	uint16_t data_offset, n_colors, hdr_size;
 
 	if (argc < 3) {
 		usage(argv[0]);
@@ -108,7 +108,12 @@ int main (int argc, char *argv[])
 	skip_bytes (fp, 8);
 	if (fread (&data_offset, sizeof (uint16_t), 1, fp) != 1)
 		error ("Couldn't read bitmap data offset", fp);
-	skip_bytes (fp, 6);
+	skip_bytes(fp, 2);
+	if (fread(&hdr_size,   sizeof(uint16_t), 1, fp) != 1)
+		error("Couldn't read bitmap header size", fp);
+	if (hdr_size < 40)
+		error("Invalid bitmap header", fp);
+	skip_bytes(fp, 2);
 	if (fread (&b->width,   sizeof (uint16_t), 1, fp) != 1)
 		error ("Couldn't read bitmap width", fp);
 	skip_bytes (fp, 2);
@@ -117,7 +122,7 @@ int main (int argc, char *argv[])
 	skip_bytes (fp, 22);
 	if (fread (&n_colors, sizeof (uint16_t), 1, fp) != 1)
 		error ("Couldn't read bitmap colors", fp);
-	skip_bytes (fp, 6);
+	skip_bytes(fp, hdr_size - 34);
 
 	/*
 	 * Repair endianess.
Signature · 1 line
2.14.2
#1 lore raw
Quoted 6 lines · Jon Smith

All BMP files were being treated as though they had a 40 byte header. There are several BMP header formats consisting of additional data. This was causing some of the header to be read as color information, skewing the color palette.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171016/b015d48b/attachment.sig>