GCVE Workshop - 22 September 2026 (14:00-18:00), Luxembourg Before The Vulnopticon Conference - Registration

GCVE-1988-2026-0324

Vulnerability from gna-1988 – Published: 2026-09-11 07:55 – Updated: 2026-09-11 07:55
VLAI
Title
PHP 8.5.7 `levenshtein()` signed-integer overflow
Summary
# PHP 8.5.7 `levenshtein()` signed-integer overflow **Author:** Khashayar Fereidani **Disclosure Date:** 2026-06-18 **Advisory:** https://fereidani.com/php-857-levenshtein-signed-integer-overflow **Contact:** https://fereidani.com/contact ## Description The `levenshtein()` function calculates the Levenshtein distance between two strings, optionally accepting custom costs for insertion, replacement, and deletion operations. In PHP 8.5.7, the implementation lacks proper bounds checking for these cost parameters. When exceptionally large values (such as `PHP_INT_MAX`) are provided, the arithmetic operations within the `reference_levdist()` function in `ext/standard/levenshtein.c` result in a signed-integer overflow. This triggers undefined behavior in C and causes the function to return a negative distance, which is mathematically invalid. ## Proof of concept ```php <?php /* * levenshtein() signed-integer overflow * File: ext/standard/levenshtein.c reference_levdist() lines 47, 50, 53-58 * * The user-supplied costs (cost_ins / cost_rep / cost_del, all zend_long) are * added with NO overflow check, e.g.: * p1[i2] = i2 * cost_ins; // line 47 * p2[0] = p1[0] + cost_del; // line 50 * c1 = p1[i2 + 1] + cost_del;// line 54 <-- PHP_INT_MAX + PHP_INT_MAX * c2 = p2[i2] + cost_ins; // line 58 * * Result: signed overflow (undefined behaviour in C) producing a * NEGATIVE edit distance, a value that is mathematically impossible. */ var_dump(levenshtein('a', 'b', PHP_INT_MAX, PHP_INT_MAX, PHP_INT_MAX)); // int(-2) (should be PHP_INT_MAX) var_dump(levenshtein('a', 'abc', PHP_INT_MAX, PHP_INT_MAX, PHP_INT_MAX)); // int(-4) var_dump(levenshtein('a', 'b', PHP_INT_MAX, 0, PHP_INT_MAX)); // int(-2) echo "All three distances are negative => signed overflow (expected >= 0).\n"; ``` ## Impact The primary risk associated with this vulnerability is an application logic flaw. Applications that rely on the `levenshtein()` function to determine string similarity or calculate distance metrics might fail to handle negative returns properly (for instance, treating a negative number as `< threshold`). This can result in unexpected behavior, incorrect data processing, or bypasses in business logic. Since it involves integer overflow producing a negative result rather than a memory corruption issue, the scope is generally limited to logic disruption rather than arbitrary code execution. ## Solution To effectively address this issue, bounds checking should be implemented either on the cost parameters at the start of the function, or during intermediate calculations. Utilizing safe arithmetic macros provided by the Zend Engine can prevent the integer overflow constraints from being violated: ```c // Example: Adding overflow safeguards in ext/standard/levenshtein.c if (UNEXPECTED(ZEND_SIGNED_ADD_OVERFLOWS(p1[i2 + 1], cost_del))) { php_error_docref(NULL, E_WARNING, "Levenshtein distance calculation caused an integer overflow"); // Handle error, e.g., return -1 or cap } ``` An alternative and proactive measure is to restrict the inputs for `cost_ins`, `cost_rep`, and `cost_del` before computing the distance, ensuring that they wouldn't exceed `ZEND_LONG_MAX` when scaled relative to the strings' lengths. _______________________________________________ Sent through the Full Disclosure mailing list https://nmap.org/mailman/listinfo/fulldisclosure Web Archives & RSS: https://seclists.org/fulldisclosure/
Severity
No CVSS data available.
Impacted products
Vendor Product Version CPE status
Php PHP Affected: unknown
guessed Create a notification for this product.

{
  "containers": {
    "cna": {
      "affected": [
        {
          "product": "PHP",
          "vendor": "Php",
          "versions": [
            {
              "status": "affected",
              "version": "unknown"
            }
          ]
        }
      ],
      "credits": [
        {
          "lang": "en",
          "type": "finder",
          "value": "Khashayar Fereidani"
        }
      ],
      "descriptions": [
        {
          "lang": "en",
          "value": "# PHP 8.5.7 `levenshtein()` signed-integer overflow\n\n**Author:** Khashayar Fereidani\n**Disclosure Date:** 2026-06-18\n**Advisory:** https://fereidani.com/php-857-levenshtein-signed-integer-overflow\n**Contact:** https://fereidani.com/contact\n\n## Description\n\nThe `levenshtein()` function calculates the Levenshtein distance\nbetween two strings, optionally accepting custom costs for insertion,\nreplacement, and deletion operations. In PHP 8.5.7, the implementation\nlacks proper bounds checking for these cost parameters. When\nexceptionally large values (such as `PHP_INT_MAX`) are provided, the\narithmetic operations within the `reference_levdist()` function in\n`ext/standard/levenshtein.c` result in a signed-integer overflow. This\ntriggers undefined behavior in C and causes the function to return a\nnegative distance, which is mathematically invalid.\n\n## Proof of concept\n\n```php\n\u003c?php\n/*\n * levenshtein() signed-integer overflow\n * File:  ext/standard/levenshtein.c  reference_levdist()  lines 47, 50, 53-58\n *\n * The user-supplied costs (cost_ins / cost_rep / cost_del, all zend_long) are\n * added with NO overflow check, e.g.:\n *     p1[i2]  = i2 * cost_ins;        // line 47\n *     p2[0]   = p1[0] + cost_del;     // line 50\n *     c1      = p1[i2 + 1] + cost_del;// line 54   \u003c-- PHP_INT_MAX +\nPHP_INT_MAX\n *     c2      = p2[i2] + cost_ins;    // line 58\n *\n * Result: signed overflow (undefined behaviour in C) producing a\n * NEGATIVE edit distance, a value that is mathematically impossible.\n */\nvar_dump(levenshtein(\u0027a\u0027,   \u0027b\u0027,   PHP_INT_MAX, PHP_INT_MAX,\nPHP_INT_MAX)); // int(-2)  (should be PHP_INT_MAX)\nvar_dump(levenshtein(\u0027a\u0027,   \u0027abc\u0027, PHP_INT_MAX, PHP_INT_MAX,\nPHP_INT_MAX)); // int(-4)\nvar_dump(levenshtein(\u0027a\u0027,   \u0027b\u0027,   PHP_INT_MAX, 0,\nPHP_INT_MAX)); // int(-2)\necho \"All three distances are negative =\u003e signed overflow (expected \u003e= 0).\\n\";\n```\n\n## Impact\n\nThe primary risk associated with this vulnerability is an application\nlogic flaw. Applications that rely on the `levenshtein()` function to\ndetermine string similarity or calculate distance metrics might fail\nto handle negative returns properly (for instance, treating a negative\nnumber as `\u003c threshold`). This can result in unexpected behavior,\nincorrect data processing, or bypasses in business logic. Since it\ninvolves integer overflow producing a negative result rather than a\nmemory corruption issue, the scope is generally limited to logic\ndisruption rather than arbitrary code execution.\n\n## Solution\n\nTo effectively address this issue, bounds checking should be\nimplemented either on the cost parameters at the start of the\nfunction, or during intermediate calculations. Utilizing safe\narithmetic macros provided by the Zend Engine can prevent the integer\noverflow constraints from being violated:\n\n```c\n// Example: Adding overflow safeguards in ext/standard/levenshtein.c\nif (UNEXPECTED(ZEND_SIGNED_ADD_OVERFLOWS(p1[i2 + 1], cost_del))) {\n    php_error_docref(NULL, E_WARNING, \"Levenshtein distance\ncalculation caused an integer overflow\");\n    // Handle error, e.g., return -1 or cap\n}\n```\nAn alternative and proactive measure is to restrict the inputs for\n`cost_ins`, `cost_rep`, and `cost_del` before computing the distance,\nensuring that they wouldn\u0027t exceed `ZEND_LONG_MAX` when scaled\nrelative to the strings\u0027 lengths.\n_______________________________________________\nSent through the Full Disclosure mailing list\nhttps://nmap.org/mailman/listinfo/fulldisclosure\nWeb Archives \u0026 RSS: https://seclists.org/fulldisclosure/"
        }
      ],
      "providerMetadata": {
        "dateUpdated": "2026-09-11T07:55:54Z",
        "orgId": "4e2abfbf-4a2a-4b76-a4e0-d77c18ba156c",
        "shortName": "VULNARCHIVE"
      },
      "references": [
        {
          "tags": [
            "technical-description",
            "exploit"
          ],
          "url": "https://vuln.freearchive.org/archive/full-disclosure/2026/Jun/14"
        },
        {
          "tags": [
            "technical-description"
          ],
          "url": "https://seclists.org/fulldisclosure/2026/Jun/14"
        },
        {
          "url": "https://fereidani.com/contact"
        },
        {
          "url": "https://fereidani.com/php-857-levenshtein-signed-integer-overflow"
        },
        {
          "url": "https://nmap.org/mailman/listinfo/fulldisclosure"
        },
        {
          "url": "https://seclists.org/fulldisclosure/"
        }
      ],
      "source": {
        "defect": [
          "https://seclists.org/fulldisclosure/2026/Jun/14"
        ],
        "discovery": "EXTERNAL"
      },
      "title": "PHP 8.5.7 `levenshtein()` signed-integer overflow",
      "x_gcve": [
        {
          "recordType": "advisory",
          "relationships": [],
          "vulnId": "GCVE-1988-2026-0324",
          "x_vulnarchive": {
            "archiveUrl": "https://vuln.freearchive.org/archive/full-disclosure/2026/Jun/14",
            "automated": true,
            "contentSha256": "54ccbc6a18fd6848395a0e5ccaba0bdf597e494673869b58873d3da2a33396eb",
            "evidenceScore": 9,
            "messageId": "",
            "originalUrl": "https://seclists.org/fulldisclosure/2026/Jun/14",
            "policy": "vulnarchive-1",
            "sourceFormat": "text/html",
            "sourcePublishedAt": "2026-06-19T06:26:09Z"
          }
        }
      ]
    }
  },
  "cveMetadata": {
    "assignerOrgId": "4e2abfbf-4a2a-4b76-a4e0-d77c18ba156c",
    "assignerShortName": "VULNARCHIVE",
    "datePublished": "2026-09-11T07:55:54Z",
    "dateUpdated": "2026-09-11T07:55:54Z",
    "state": "PUBLISHED",
    "vulnId": "GCVE-1988-2026-0324"
  },
  "dataType": "CVE_RECORD",
  "dataVersion": "5.2"
}



Log in or create an account to share your comment.




Tags
Taxonomy of the tags.


Loading…

Loading…

Loading…

Forecast uses a logistic model when the trend is rising, or an exponential decay model when the trend is falling. Fitted via linearized least squares.

Sightings

Author Source Type Date Other

Nomenclature

  • Seen: The vulnerability was mentioned, discussed, or observed by the user.
  • Confirmed: The vulnerability has been validated from an analyst's perspective.
  • Published Proof of Concept: A public proof of concept is available for this vulnerability.
  • Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
  • Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
  • Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
  • Not confirmed: The user expressed doubt about the validity of the vulnerability.
  • Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.

Loading…

Detection rules are retrieved from Rulezet.

Loading…

Loading…

Related by attack behaviour

Vulnerabilities whose description is nearest to this one in the vector space of the CIRCL/vulnerability-attack-technique-biencoder model. This is a similarity search over the bi-encoder space (plain cosine), not a classification, and it has no measured accuracy.


Loading…