Commit 2c4cfc3
committed
Fix UTF-8 expansion/truncation error during fetch
On IBM i, we bind character strings to UTF-8, which breaks the
1 character = 1 code unit assumption of the code. LUW uses UTF-16
instead, which AFAICT doesn't have this problem (since I can't
find any encoding which maps from fewer than 4 bytes to a Unicode
code point above U+FFFF).
This results in a buffer that may be too small to hold the entire
result and the result is truncated - however the indicator value
is set to the length of the total data. To make problems worse,
the code assumes that the indicator value is less than the size of
the buffer and reads the length given. In the case of truncation,
this assumption is incorrect and the result is a buffer over-read,
and attempting to decode random bytes as UTF-8. If those bytes are
not valid, this can cause an error similar to the following:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb2 in position 22: invalid start byte
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/QOpenSys/pkgs/lib/python3.6/site-packages/ibm_db_dbi.py", line 1472, in _fetch_helper
row = ibm_db.fetch_tuple(self.stmt_handler)
SystemError: <built-in function fetch_tuple> returned a result with an error set
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "example.py", line 14, in <module>
cur.fetchone()
File "/QOpenSys/pkgs/lib/python3.6/site-packages/ibm_db_dbi.py", line 1492, in fetchone
row_list = self._fetch_helper(1)
File "/QOpenSys/pkgs/lib/python3.6/site-packages/ibm_db_dbi.py", line 1476, in _fetch_helper
raise self.messages[-1]
ibm_db_dbi.Error: ibm_db_dbi::Error: SystemError('<built-in function fetch_tuple> returned a result with an error set',)1 parent 8bc7086 commit 2c4cfc3
1 file changed
+20
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1056 | 1056 | | |
1057 | 1057 | | |
1058 | 1058 | | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
1059 | 1067 | | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
1060 | 1079 | | |
1061 | 1080 | | |
1062 | 1081 | | |
| |||
8357 | 8376 | | |
8358 | 8377 | | |
8359 | 8378 | | |
8360 | | - | |
| 8379 | + | |
8361 | 8380 | | |
8362 | 8381 | | |
8363 | 8382 | | |
| |||
0 commit comments