Repository navigation
ADBM-3574: Fix JSON support for pgbackrest recovery filters #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2.54-ci
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -819,12 +819,12 @@ jsonReadSkipStr(JsonRead *const this) | |||||
| { | ||||||
| this->json++; | ||||||
|
|
||||||
| // Expect four digits | ||||||
| // Expect four hex digits | ||||||
| unsigned int digitIdx = 0; | ||||||
|
|
||||||
| for (; digitIdx < 4; digitIdx++) | ||||||
| { | ||||||
| if (!isdigit(this->json[digitIdx])) | ||||||
| if (!isxdigit(this->json[digitIdx])) | ||||||
| break; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -937,6 +937,60 @@ jsonReadSkip(JsonRead *const this) | |||||
| FUNCTION_TEST_RETURN_VOID(); | ||||||
| } | ||||||
|
|
||||||
| /**********************************************************************************************************************************/ | ||||||
| FN_EXTERN void | ||||||
| jsonDecodeUnicode(JsonRead *const this, String *const result) | ||||||
| { | ||||||
| this->json++; // get past /u | ||||||
|
Comment on lines
+941
to
+944
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add |
||||||
| const unsigned int high = cvtZSubNToUIntBase(this->json, 0, 4, 16); | ||||||
| unsigned int codepoint = high; | ||||||
| this->json += 4; | ||||||
|
|
||||||
| // Check for supplementary planes | ||||||
| if (high >= 0xD800 && high <= 0xDBFF) | ||||||
| { | ||||||
| if (*this->json != '\\' || *(this->json + 1) != 'u') | ||||||
| THROW_FMT(JsonFormatError, "missing low surrogate for high surrogate at: %s", this->json - 6); | ||||||
|
|
||||||
| this->json += 2; | ||||||
| const unsigned int low = cvtZSubNToUIntBase(this->json, 0, 4, 16); | ||||||
| this->json += 4; | ||||||
|
|
||||||
| if (low < 0xDC00 || low > 0xDFFF) | ||||||
| THROW_FMT(JsonFormatError, "invalid low surrogate in unicode escape at: %s", this->json - 6); | ||||||
|
|
||||||
| codepoint = 0x10000 + ((high - 0xD800) << 10) + (low - 0xDC00); | ||||||
| } | ||||||
| else if (high >= 0xDC00 && high <= 0xDFFF) | ||||||
| THROW_FMT(JsonFormatError, "unexpected low surrogate without high surrogate at: %s", this->json - 4); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
to add |
||||||
|
|
||||||
| // Append 1-4 bytes to the result | ||||||
| if (codepoint <= 0x7F) | ||||||
| { | ||||||
| strCatChr(result, (char)codepoint); | ||||||
| } | ||||||
| else if (codepoint <= 0x7FF) | ||||||
| { | ||||||
| strCatChr(result, (char)(0xC0 | (codepoint >> 6))); | ||||||
| strCatChr(result, (char)(0x80 | (codepoint & 0x3F))); | ||||||
| } | ||||||
| else if (codepoint <= 0xFFFF) | ||||||
| { | ||||||
| strCatChr(result, (char)(0xE0 | (codepoint >> 12))); | ||||||
| strCatChr(result, (char)(0x80 | ((codepoint >> 6) & 0x3F))); | ||||||
| strCatChr(result, (char)(0x80 | (codepoint & 0x3F))); | ||||||
| } | ||||||
| else | ||||||
| { | ||||||
| strCatChr(result, (char)(0xF0 | (codepoint >> 18))); | ||||||
| strCatChr(result, (char)(0x80 | ((codepoint >> 12) & 0x3F))); | ||||||
| strCatChr(result, (char)(0x80 | ((codepoint >> 6) & 0x3F))); | ||||||
| strCatChr(result, (char)(0x80 | (codepoint & 0x3F))); | ||||||
| } | ||||||
|
Comment on lines
+972
to
+989
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these lines are not covered by tests
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is precisely why the CI is red: it checks the coverage of the ENTIRE codebase. |
||||||
|
|
||||||
| this->json--; | ||||||
| } | ||||||
|
|
||||||
|
Comment on lines
+940
to
+993
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
| /**********************************************************************************************************************************/ | ||||||
| FN_EXTERN String * | ||||||
| jsonReadStr(JsonRead *const this) | ||||||
|
|
@@ -1016,17 +1070,7 @@ jsonReadStr(JsonRead *const this) | |||||
|
|
||||||
| case 'u': | ||||||
| { | ||||||
| this->json++; | ||||||
|
|
||||||
| // We don't know how to decode anything except ASCII so fail if it looks like Unicode | ||||||
| if (strncmp(this->json, "00", 2) != 0) | ||||||
| THROW_FMT(JsonFormatError, "unable to decode at: %s", this->json - 2); | ||||||
|
|
||||||
| // Decode char | ||||||
| this->json += 2; | ||||||
| strCatChr(result, (char)cvtZSubNToUIntBase(this->json, 0, 2, 16)); | ||||||
| this->json++; | ||||||
|
|
||||||
| jsonDecodeUnicode(this, result); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now |
||||||
| break; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,6 +89,9 @@ FN_EXTERN Variant *jsonReadVar(JsonRead *this); | |
| /*********************************************************************************************************************************** | ||
| Read Helper Functions | ||
| ***********************************************************************************************************************************/ | ||
| // Unicode escape | ||
| FN_EXTERN void jsonDecodeUnicode(JsonRead *this, String *result); | ||
|
|
||
| // Convert JSON to Variant | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you make this function public? |
||
| FN_EXTERN Variant *jsonToVar(const String *json); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A
\before\0injsonReadSkipStrcauses the pointer to move past the end of the string (fixed upstream in pgbackrest/pgbackrest@b623071a2).