diff --git a/CHANGES.md b/CHANGES.md index 7829fa4..325c506 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,7 @@ v1.4.1 - YYYY-MM-DD - Fixed the link libraries for the example source code (Issue #86) - Fixed handling of the Info object (Issue #87) +- Fixed opening of PDF files less than 1024 bytes in length (Issue #87) v1.4.0 - 2024-12-26 diff --git a/pdfio-common.c b/pdfio-common.c index e795687..0a8b49a 100644 --- a/pdfio-common.c +++ b/pdfio-common.c @@ -1,7 +1,7 @@ // // Common support functions for pdfio. // -// Copyright © 2021-2024 by Michael R Sweet. +// Copyright © 2021-2025 by Michael R Sweet. // // Licensed under Apache License v2.0. See the file "LICENSE" for more // information. @@ -398,7 +398,10 @@ _pdfioFileSeek(pdfio_file_t *pdf, // I - PDF file } // Seek within the file... - if ((offset = lseek(pdf->fd, offset, whence)) < 0) + if ((offset = lseek(pdf->fd, offset, whence)) < 0 && whence == SEEK_END && errno == EINVAL) + offset = lseek(pdf->fd, 0, SEEK_SET); + + if (offset < 0) { _pdfioFileError(pdf, "Unable to seek within file - %s", strerror(errno)); return (-1);