Index: uspace/lib/gfximage/src/tga.c
===================================================================
--- uspace/lib/gfximage/src/tga.c	(revision fd05ea65d3ce558eba4ac6cd5b55b70eebc1fcf5)
+++ uspace/lib/gfximage/src/tga.c	(revision aba2d04878ae87232f1a04b6539d16fd7d74a626)
@@ -155,5 +155,15 @@
 	tga->img_alpha_dir = (head->img_descr & 0xf0) >> 4;
 	tga->img_data = tga->cmap_data + tga->cmap_length;
-	tga->img_length = ALIGN_UP(tga->width * tga->height * tga->img_bpp, 8) >> 3;
+
+	uint64_t length = (uint64_t) tga->width * tga->height * tga->img_bpp;
+	if (length & 0x7)
+		length += 8;
+	length >>= 3;
+
+	if (length > SIZE_MAX - sizeof(tga_header_t) - tga->id_length -
+	    tga->cmap_length)
+		return false;
+
+	tga->img_length = length;
 
 	if (size < sizeof(tga_header_t) + tga->id_length +
