forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit8555173
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 parent2fb7560 commit8555173
File tree
2 files changed
+10
-2
lines changed- src
- common
- test/modules/test_json_parser/t
2 files changed
+10
-2
lines changedLines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1689 | 1689 |
| |
1690 | 1690 |
| |
1691 | 1691 |
| |
1692 |
| - | |
1693 |
| - | |
| 1692 | + | |
| 1693 | + | |
1694 | 1694 |
| |
1695 | 1695 |
| |
1696 | 1696 |
| |
|
Lines changed: 8 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
127 | 127 |
| |
128 | 128 |
| |
129 | 129 |
| |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
130 | 138 |
|
0 commit comments
Comments
(0)