forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit377c25d
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 parentb99dc66 commit377c25d
1 file changed
+3
-2
lines changedLines changed: 3 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
686 | 686 |
| |
687 | 687 |
| |
688 | 688 |
| |
| 689 | + | |
689 | 690 |
| |
690 | 691 |
| |
691 | 692 |
| |
| |||
697 | 698 |
| |
698 | 699 |
| |
699 | 700 |
| |
700 |
| - | |
701 |
| - | |
| 701 | + | |
| 702 | + | |
702 | 703 |
| |
703 | 704 |
| |
704 | 705 |
| |
|
0 commit comments
Comments
(0)