levenshtein integer overflow
Open
Nobody has claimed this yet.
Bug
Extension: standard
Status: Verified
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
The following code:
<?php
echo levenshtein('aa', 'ab', 1, PHP_INT_MAX, 1);
Resulted in this output:
-9223372036854775807
But I expected this output instead:
2
Also levenshtein(str_repeat('a', 100000), str_repeat('b', 1000000), 1, PHP_INT_MAX - 500000, 1)
returning unexpected -9223372036854625811
PHP Version
any
Operating System
any 64-bit
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the two levenshtein examples from the issue on a 64-bit system and inspect the implementation and existing tests for levenshtein. Trace how large insertion, replacement, and deletion costs are handled, then add regression coverage showing the expected result of 2 without integer overflow.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100