Skip to content

Commit

Permalink
Fix Issue #750 : bmp read failure on sparc64 due to data misalignment
Browse files Browse the repository at this point in the history
* The bmp infoheader on the sparc64 is not aligned on a 32-bit word, so
  read the data byte by byte.
  • Loading branch information
DanBloomberg committed Oct 11, 2024
1 parent 627c066 commit af59899
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/bmpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,12 @@ pixReadMemBmp(const l_uint8 *cdata,
size_t size)
{
l_uint8 pel[4];
l_uint8 *cmapBuf, *fdata, *data;
l_uint8 *cmapBuf, *fdata, *data, *bmpih_b;
l_int16 bftype, depth, d;
l_int32 offset, ihbytes, width, height, height_neg, xres, yres, spp;
l_int32 offset, width, height, height_neg, xres, yres, spp;
l_int32 compression, imagebytes, fdatabytes, cmapbytes, ncolors, maxcolors;
l_int32 fdatabpl, extrabytes, filebpp, pixWpl, pixBpl, i, j, k;
l_uint32 ihbytes;
l_uint32 *line, *pixdata, *pword;
l_int64 npixels;
BMP_FH *bmpfh;
Expand Down Expand Up @@ -177,8 +178,13 @@ PIXCMAP *cmap;
offset += (l_uint32)bmpfh->bfOffBits[3] << 24;

/* Read the remaining useful data in the infoheader.
* Note that the first 4 bytes give the infoheader size. */
ihbytes = convertOnBigEnd32(*(l_uint32 *)(bmpih));
* Note that the first 4 bytes give the infoheader size.
* The infoheader pointer on sparc64 is not 32-bit aligned. */
bmpih_b = (l_uint8 *)bmpih;
ihbytes = *bmpih_b + (*(bmpih_b + 1) << 8) +
(*(bmpih_b + 2) << 16) + (*(bmpih_b + 3) << 24);
ihbytes = convertOnBigEnd32(ihbytes);
/* lept_stderr("ihbytes = %d\n", ihbytes); */
width = convertOnBigEnd32(bmpih->biWidth);
height = convertOnBigEnd32(bmpih->biHeight);
depth = convertOnBigEnd16(bmpih->biBitCount);
Expand Down

0 comments on commit af59899

Please sign in to comment.