forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit8c3f30e
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 parent6a458d9 commit8c3f30e
1 file changed
+3
-2
lines changedLines changed: 3 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
680 | 680 |
| |
681 | 681 |
| |
682 | 682 |
| |
| 683 | + | |
683 | 684 |
| |
684 | 685 |
| |
685 | 686 |
| |
| |||
691 | 692 |
| |
692 | 693 |
| |
693 | 694 |
| |
694 |
| - | |
695 |
| - | |
| 695 | + | |
| 696 | + | |
696 | 697 |
| |
697 | 698 |
| |
698 | 699 |
| |
|
0 commit comments
Comments
(0)