diff options
| author | Christoph Berg | 2023-09-14 12:10:38 +0000 |
|---|---|---|
| committer | Christoph Berg | 2023-09-14 12:10:38 +0000 |
| commit | 685f2ccac2be7c3183b05552cdca4d087a4e62db (patch) | |
| tree | 4cb8262a29aec6cf5d28556462b6c78d8dd5a994 | |
| parent | c7128ed74c3488e95eb8509cd9875cde979ef90b (diff) | |
Decode oid/xid >= 2^31 correctly
Spotted by alexandervpotapov.
Close #18.
| -rw-r--r-- | decode.c | 28 | ||||
| -rw-r--r-- | expected/datatypes.out | 4 | ||||
| -rw-r--r-- | expected/datatypes_3.out | 4 |
3 files changed, 30 insertions, 6 deletions
@@ -67,6 +67,9 @@ static int decode_int(const char *buffer, unsigned int buff_size, unsigned int *out_size); static int +decode_uint(const char *buffer, unsigned int buff_size, unsigned int *out_size); + +static int decode_bigint(const char *buffer, unsigned int buff_size, unsigned int *out_size); static int @@ -144,10 +147,10 @@ static ParseCallbackTableItem callback_table[] = "int", &decode_int }, { - "oid", &decode_int + "oid", &decode_uint }, { - "xid", &decode_int + "xid", &decode_uint }, { "serial", &decode_int @@ -702,6 +705,27 @@ decode_int(const char *buffer, unsigned int buff_size, unsigned int *out_size) return 0; } +/* Decode an unsigned int type */ +static int +decode_uint(const char *buffer, unsigned int buff_size, unsigned int *out_size) +{ + const char *new_buffer = (const char *) INTALIGN(buffer); + unsigned int delta = (unsigned int) ((uintptr_t) new_buffer - (uintptr_t) buffer); + + if (buff_size < delta) + return -1; + + buff_size -= delta; + buffer = new_buffer; + + if (buff_size < sizeof(uint32)) + return -2; + + CopyAppendFmt("%u", *(uint32 *) buffer); + *out_size = sizeof(uint32) + delta; + return 0; +} + /* Decode a bigint type */ static int decode_bigint(const char *buffer, unsigned int buff_size, unsigned int *out_size) diff --git a/expected/datatypes.out b/expected/datatypes.out index ff2aae2..a13c19e 100644 --- a/expected/datatypes.out +++ b/expected/datatypes.out @@ -516,7 +516,7 @@ Block 0 ******************************************************** <Data> ----- Item 1 -- Length: 28 Offset: 8160 (0x1fe0) Flags: NORMAL -COPY: -1 +COPY: 4294967295 Item 2 -- Length: 28 Offset: 8128 (0x1fc0) Flags: NORMAL COPY: 0 Item 3 -- Length: 28 Offset: 8096 (0x1fa0) Flags: NORMAL @@ -972,7 +972,7 @@ Block 0 ******************************************************** <Data> ----- Item 1 -- Length: 28 Offset: 8160 (0x1fe0) Flags: NORMAL -COPY: -1 +COPY: 4294967295 Item 2 -- Length: 28 Offset: 8128 (0x1fc0) Flags: NORMAL COPY: 0 Item 3 -- Length: 28 Offset: 8096 (0x1fa0) Flags: NORMAL diff --git a/expected/datatypes_3.out b/expected/datatypes_3.out index 9620cea..beaedba 100644 --- a/expected/datatypes_3.out +++ b/expected/datatypes_3.out @@ -516,7 +516,7 @@ Block 0 ******************************************************** <Data> ----- Item 1 -- Length: 28 Offset: 8164 (0x1fe4) Flags: NORMAL -COPY: -1 +COPY: 4294967295 Item 2 -- Length: 28 Offset: 8136 (0x1fc8) Flags: NORMAL COPY: 0 Item 3 -- Length: 28 Offset: 8108 (0x1fac) Flags: NORMAL @@ -972,7 +972,7 @@ Block 0 ******************************************************** <Data> ----- Item 1 -- Length: 28 Offset: 8164 (0x1fe4) Flags: NORMAL -COPY: -1 +COPY: 4294967295 Item 2 -- Length: 28 Offset: 8136 (0x1fc8) Flags: NORMAL COPY: 0 Item 3 -- Length: 28 Offset: 8108 (0x1fac) Flags: NORMAL |
