Skip to content

Commit

Permalink
Fixed buffer alignment problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurence Bank authored and Laurence Bank committed Apr 14, 2024
1 parent b7dcf60 commit 811135e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=PNGdec
version=1.0.1
version=1.0.2
author=Larry Bank
maintainer=Larry Bank
sentence=Universal PNG decoder for MCUs with at least 48K of RAM.
Expand Down
30 changes: 22 additions & 8 deletions src/png.inl
Original file line number Diff line number Diff line change
Expand Up @@ -782,11 +782,19 @@ PNG_STATIC int DecodePNG(PNGIMAGE *pPage, void *pUser, int iOptions)
// number of bytes remaining in buffer
iBytesRead -= iOffset;
}
d_stream.next_in = &pPage->ucFileBuf[iOffset];
d_stream.avail_in = iBytesRead;
iLen -= iBytesRead;
if (iLen < 0) iLen = 0;
iOffset += iBytesRead;
if (iBytesRead > iLen) { // we read too much
d_stream.next_in = &pPage->ucFileBuf[iOffset];
d_stream.avail_in = iLen;
iOffset += iLen; // point to start of next marker
iBytesRead -= iLen; // keep remaining byte count
iLen = 0; // every byte will be decoded
} else {
d_stream.next_in = &pPage->ucFileBuf[iOffset];
d_stream.avail_in = iBytesRead;
iLen -= iBytesRead;
iOffset += iBytesRead;
iBytesRead = 0;
}
// if (iMarker == 0x66644154) // data starts at offset 4 in APNG frame data block
// {
// d_stream.next_in += 4;
Expand Down Expand Up @@ -840,9 +848,15 @@ PNG_STATIC int DecodePNG(PNGIMAGE *pPage, void *pUser, int iOptions)
} // while (iLen)
if (y != pPage->iHeight && iFileOffset < pPage->PNGFile.iSize) {
// need to read more IDAT chunks
iBytesRead = (*pPage->pfnRead)(&pPage->PNGFile, pPage->ucFileBuf, PNG_FILE_BUF_SIZE);
iFileOffset += iBytesRead;
iOffset = 0;
if (iBytesRead) { // data remaining in buffer
// move the data down
memmove(pPage->ucFileBuf, &pPage->ucFileBuf[iOffset], iBytesRead);
iOffset = 0;
} else {
iBytesRead = (*pPage->pfnRead)(&pPage->PNGFile, pPage->ucFileBuf, PNG_FILE_BUF_SIZE);
iFileOffset += iBytesRead;
iOffset = 0;
}
}
break;
// case 0x69545874: //'iTXt'
Expand Down

0 comments on commit 811135e

Please sign in to comment.