[CONC-584] fetching timy values above 127 returns. MYSQL_DATA_TRUNCATED Created: 2022-03-14  Updated: 2022-03-15  Resolved: 2022-03-15

Status: Closed
Project: MariaDB Connector/C
Component/s: Prepared Statements
Affects Version/s: 3.2.6
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Andreas Banf Assignee: Georg Richter
Resolution: Not a Bug Votes: 0
Labels: MYSQL_DATA_TRUNCATED, TINY
Environment:

mariadb 10.7.3.1
tumbleweed kernel 5.16.11 x86_64


Attachments: File table.sql     File tinyerr.c    

 Description   

mysql_stmt_fetch() returns MYSQL_DATA_TRUNCATED when fetching TINYINT UNSiGNED from DB with values above 127. Fetched values seem nevertheless to be correct in range 0 to 255.

Consecutive fetches return return-code of 1st fetch, regardless of read value.
Latter observation not verified.

attached test produces:
for i in 1 2 3 4 9 ; do ./a.out $i ; done
id 1: tiny 127
id 2: data truncated --> id 2: tiny 128
id 3: tiny 32
id 4: data truncated --> id 4: tiny 192
id 9: no data --> id 9: tiny 0



 Comments   
Comment by Andreas Banf [ 2022-03-15 ]

Issue is not restricted to TINY. SMALLINT, INT, BIGINT are affected in a similar way, i.e. values with MSB set will let the fetch-statement return DATA_TRUNCATED. Obviously the connector interprets all integer data from db as signed. So the value 128 will need 16 bits, the lower bits identical to unsigned char value 128, the sign bit 0 for + in the higher 8 bits. In effect, one gets the correct value, but the sign bit ( as 0) is truncated as indicated by the return code.

If the connector cannot detect whether a read integer is signed or unsigned, the programmer should be enabled to define this by additional enumerations, e.g. MYSQL_TYPE_UTINY for unsigned tiny/char.
A simple solution may be that the connector interprets all ipositive ntegers as unsigned when calculating the needed size. Thereby cases where length definitions in connector and db are identical would be handled correcly.

Comment by Georg Richter [ 2022-03-15 ]

After initializing the MYSQL_BIND array, the is_unsigned member is set to 0, therefore truncation will be indicated if the fetched value doesn't fit into signed type.

Generated at Thu Feb 08 03:06:21 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.