forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit5396a29
committed
Fix overread in JSON parsing errors for incomplete byte sequences
json_lex_string() relies on pg_encoding_mblen_bounded() to point to theend of a JSON string when generating an error message, and the input ituses is not guaranteed to be null-terminated.It was possible to walk off the end of the input buffer by a few byteswhen the last bytes consist of an incomplete multi-byte sequence, astoken_terminator would point to a location defined bypg_encoding_mblen_bounded() rather than the end of the input. Thiscommit switches token_terminator so as the error uses data up to theend of the JSON input.More work should be done so as this code could rely on an equivalent ofreport_invalid_encoding() so as incorrect byte sequences can show inerror messages in a readable form. This requires work for at least twocases in the JSON parsing API: an incomplete token and an invalid escapesequence. A more complete solution may be too invasive for a backpatch,so this is left as a future improvement, taking care of the overreadfirst.A test is added on HEAD as test_json_parser makes this issuestraight-forward to check.Note that pg_encoding_mblen_bounded() no longer has any callers. Thiswill be removed on HEAD with a separate commit, as this is proving toencourage unsafe coding.Author: Jacob ChampionDiscussion:https://postgr.es/m/CAOYmi+ncM7pwLS3AnKCSmoqqtpjvA8wmCdoBtKA3ZrB2hZG6zA@mail.gmail.comBackpatch-through: 131 parent5dce8ce commit5396a29
1 file changed
+2
-2
lines changedLines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
721 | 721 |
| |
722 | 722 |
| |
723 | 723 |
| |
724 |
| - | |
725 |
| - | |
| 724 | + | |
| 725 | + | |
726 | 726 |
| |
727 | 727 |
| |
728 | 728 |
| |
|
0 commit comments
Comments
(0)