From d5173d14da59dacd0c939a881abc99eaad3c49d0 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Fri, 1 Oct 2021 11:38:04 -0400 Subject: [PATCH] Fix some Coverity-detected issues. --- CHANGES.md | 1 + pdfio-array.c | 3 ++- pdfio-content.c | 2 +- pdfio-file.c | 6 +++++- pdfio-value.c | 2 ++ ttf.c | 3 ++- 6 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 0f62462..7023a4c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,7 @@ v1.0.0 (TBD) - Added `pdfioFileCreateOutput` API to support streaming output of PDF (Issue #21) +- Fixed some issues identified by a Coverity scan. v1.0b1 (August 30, 2021) diff --git a/pdfio-array.c b/pdfio-array.c index 088ba8c..defe3f7 100644 --- a/pdfio-array.c +++ b/pdfio-array.c @@ -568,7 +568,8 @@ _pdfioArrayRead(pdfio_file_t *pdf, // I - PDF file PDFIO_DEBUG("_pdfioArrayRead(pdf=%p, tb=%p)\n", pdf, tb); // Create an array... - array = pdfioArrayCreate(pdf); + if ((array = pdfioArrayCreate(pdf)) == NULL) + return (NULL); // Read until we get "]" to end the array... while (_pdfioTokenGet(tb, token, sizeof(token))) diff --git a/pdfio-content.c b/pdfio-content.c index 6c7ff14..c020960 100644 --- a/pdfio-content.c +++ b/pdfio-content.c @@ -2358,7 +2358,7 @@ copy_png(pdfio_dict_t *dict, // I - Dictionary PDFIO_DEBUG("copy_png: Adding %s ColorSpace value.\n", color_type == _PDFIO_PNG_TYPE_GRAY ? "CalGray" : "CalRGB"); if (wx != 0.0) - pdfioDictSetArray(dict, "ColorSpace", pdfioArrayCreateColorFromPrimaries(dict->pdf, color_type == _PDFIO_PNG_TYPE_GRAY ? 1 : 3, gamma, wx, wy, rx, ry, bx, by, gx, gy)); + pdfioDictSetArray(dict, "ColorSpace", pdfioArrayCreateColorFromPrimaries(dict->pdf, color_type == _PDFIO_PNG_TYPE_GRAY ? 1 : 3, gamma, wx, wy, rx, ry, gx, gy, bx, by)); else pdfioDictSetArray(dict, "ColorSpace", pdfioArrayCreateColorFromStandard(dict->pdf, color_type == _PDFIO_PNG_TYPE_GRAY ? 1 : 3, PDFIO_CS_SRGB)); } diff --git a/pdfio-file.c b/pdfio-file.c index 45aaf8a..0dc9adb 100644 --- a/pdfio-file.c +++ b/pdfio-file.c @@ -1388,7 +1388,11 @@ load_xref(pdfio_file_t *pdf, // I - PDF file return (false); } - _pdfioFileSeek(pdf, xref_offset + ptr + 3 - line, SEEK_SET); + if (_pdfioFileSeek(pdf, xref_offset + ptr + 3 - line, SEEK_SET) < 0) + { + _pdfioFileError(pdf, "Unable to seek to xref object %lu %u.", (unsigned long)number, (unsigned)generation); + return (false); + } PDFIO_DEBUG("load_xref: Loading object %lu %u.\n", (unsigned long)number, (unsigned)generation); diff --git a/pdfio-value.c b/pdfio-value.c index f896c3f..784aa61 100644 --- a/pdfio-value.c +++ b/pdfio-value.c @@ -278,6 +278,8 @@ _pdfioValueRead(pdfio_file_t *pdf, // I - PDF file else { // Date value... + memset(&dateval, 0, sizeof(dateval)); + dateval.tm_year = (token[3] - '0') * 1000 + (token[4] - '0') * 100 + (token[5] - '0') * 10 + token[6] - '0' - 1900; dateval.tm_mon = (token[7] - '0') * 10 + token[8] - '0' - 1; dateval.tm_mday = (token[9] - '0') * 10 + token[10] - '0'; diff --git a/ttf.c b/ttf.c index 6279697..0517565 100644 --- a/ttf.c +++ b/ttf.c @@ -513,7 +513,8 @@ ttfDelete(ttf_t *font) // I - Font return; // Close the font file... - close(font->fd); + if (font->fd >= 0) + close(font->fd); // Free all memory used... free(font->copyright);