CVE-2023-24808 (C, published 2023-02-07T01:15Z)
Description: value:  PDFio is a C library for reading and writing PDF files. In versions prior to 1.1.0 a denial of service (DOS) vulnerability exists in the pdfio parser. Crafted pdf files can cause the program to run at 100% utilization and never terminate. The pdf which causes this crash found in testing is about 28kb in size and was discovered via fuzzing. Anyone who uses this library either as a standalone binary or as a library can be DOSed when attempting to parse this type of file. Web servers or other automated processes which rely on this code to turn pdf submissions into plaintext can be DOSed when an attacker uploads the pdf. Please see the linked GHSA for an example pdf. Users are advised to upgrade. There are no known workarounds for this vulnerability.
Severity: nan (CVSS v3 base score: 6.5)
Weakness: CWE-835 \u2014 Loop with Unreachable Exit Condition ('Infinite Loop')
The product contains an iteration or loop with an exit condition that cannot be reached, i.e., an infinite loop.
Repository: https://github.com/michaelrsweet/pdfio
Files changed:
CHANGES.md
Makefile
NOTICE
pdfio-common.c
pdfio-dict.c
pdfio-file.c
pdfio-object.c
pdfio-token.c
pdfio-value.c
Commit message: Fix denial-of-service attack when reading corrupt PDF files.


Vulnerable code:
v1.1.0 (Month DD, YYYY)
# Copyright © 2021-2022 by Michael R Sweet.
VERSION		=	1.1
Copyright © 2021-2022 by Michael R Sweet.
// Copyright © 2021 by Michael R Sweet.
  
// Copyright © 2021-2022 by Michael R Sweet.
  PDFIO_DEBUG("_pdfioDictSetValue(%p): ", (void *)dict);
  PDFIO_DEBUG_DICT(dict);
  PDFIO_DEBUG("\n");
// Copyright © 2021-2022 by Michael R Sweet.
// Copyright © 2021-2022 by Michael R Sweet.
// Copyright © 2021 by Michael R Sweet.
    strncpy(buffer, tb->tokens[tb->num_tokens], bufsize - 1);
    buffer[bufsize - 1] = '\0';
  PDFIO_DEBUG("_pdfioTokenRead: Read '%s'.\n", buffer);
// Copyright © 2021 by Michael R Sweet.

Fixed code:
v1.1.0 (February 3, 2023)
-------------------------
- CVE-2023-nnnn: Fixed a potential denial-of-service with corrupt PDF files.
# Copyright © 2021-2023 by Michael R Sweet.
VERSION		=	1.1.0
Copyright © 2021-2023 by Michael R Sweet.
// Copyright © 2021-2023 by Michael R Sweet.
  PDFIO_DEBUG("_pdfioFileConsume: pos=%ld\n", (long)(pdf->bufpos + pdf->bufptr - pdf->buffer));


// Copyright © 2021-2023 by Michael R Sweet.
    else if (_pdfioDictGetValue(dict, key + 1))
    {
      _pdfioFileError(pdf, "Duplicate dictionary key '%s'.", key + 1);
      return (NULL);
    }
    PDFIO_DEBUG("_pdfioDictRead: Reading value for '%s'.\n", key + 1);

//  PDFIO_DEBUG("_pdfioDictSetValue(%p): ", (void *)dict);
//  PDFIO_DEBUG_DICT(dict);
//  PDFIO_DEBUG("\n");
// Copyright © 2021-2023 by Michael R Sweet.
      PDFIO_DEBUG("load_xref: Got trailer dict.\n");

// Copyright © 2021-2023 by Michael R Sweet.
// Copyright © 2021-2023 by Michael R Sweet.
    size_t len;				// Length of token


    if ((len = strlen(tb->tokens[tb->num_tokens])) > (bufsize - 1))
    {
      // Value too large...
      PDFIO_DEBUG("_pdfioTokenGet(tb=%p, buffer=%p, bufsize=%u): Token '%s' from stack too large.\n", tb, buffer, (unsigned)bufsize, tb->tokens[tb->num_tokens]);
      *buffer = '\0';
      return (false);
    }

    memcpy(buffer, tb->tokens[tb->num_tokens], len);
    buffer[len] = '\0';
//  PDFIO_DEBUG("_pdfioTokenRead: Read '%s'.\n", buffer);
#if 0
#endif // 0
// Copyright © 2021-2023 by Michael R Sweet.