model-writtenrun 7857 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Rafi Shamim reported that substring('string' from 2 for 2147483646) incorrectly raised a negative-length error, suggesting that returning 'tring' would match other databases #1.
- Pavel Stehule supplied checked-addition guards that return the remaining text on overflow #2; Jerry Sievert pointed out that the supplied length itself is a valid integer #3, and Pavel agreed that the patch's behavior was appropriate #4.
- Tom Lane found that Pavel's patch missed negative overflow and an unchecked multiplication, then posted a revision that explicitly rejects negative lengths, checks multibyte-size multiplication, protects detoast slicing, and adds regression tests #5.
- Rafi Shamim subsequently reported the same failure in the separate bytea implementation #6, and Tom Lane identified the bit variant as another likely affected implementation in the thread's last message #7.
- Tom Lane committed the revision from #5 with additional bytea and bit fixes and tests as 4bd3fad80e, crediting Pavel Stehule jointly; the fix landed with backports through PostgreSQL 11, while older branches were excluded because they lacked the shared overflow-checking infrastructure and did not warrant a standalone implementation.