Skip to content

Fix isc_array_lookup_desc/bounds length of text arrays on attachments with another character set - #9182

Open
madorin wants to merge 1 commit into
FirebirdSQL:masterfrom
madorin:fix-array-desc-length
Open

madorin wants to merge 1 commit into
FirebirdSQL:masterfrom
madorin:fix-array-desc-length

Conversation

@madorin

@madorin madorin commented Oct 2, 2026

Copy link
Copy Markdown

Fixes #4109.

isc_array_lookup_desc / isc_array_lookup_bounds describe text elements as blr_text /
blr_varying without a character set, so isc_array_get_slice / isc_array_put_slice exchange
them in the attachment character set. But array_desc_length was RDB$FIELD_LENGTH, the length
in bytes in the column character set. On a UTF8 attachment a VARCHAR(15) column in NONE or a
single-byte character set got 15 bytes, i.e. 3 characters, and reading or writing longer values
failed with "string right truncation".

The length is now the declared number of characters (RDB$CHARACTER_LENGTH) times the bytes per
character of the attachment character set (frb_info_att_charset), as DSQL does for messages,
when it's longer than RDB$FIELD_LENGTH (limited to MAX_VARY_COLUMN_SIZE). If the attachment
character set or the character length is not known, the length doesn't change. Single-byte
attachments and UTF8 columns on UTF8 attachments get the same length as before.

Tested with a debug build of the client (master and v5.0-release) against master, 5.0.4, 3.0.14
and 2.5.9 servers: VARCHAR(15) [1:3] in NONE and WIN1251, read and written with
isc_array_lookup_bounds + isc_array_get_slice / isc_array_put_slice on UTF8 (length 60,
values correct) and WIN1251 attachments (length 15, unchanged). Writing WIN1251 columns from UTF8
also needs #9181 on the server (#9180).

The same change applies to v5.0-release (there is only the query without schemas); I can open a
separate PR for the backport if needed.

… with another character set

Text elements of the array API are exchanged in the attachment character set
(blr_text/blr_varying without a character set), but the length was the column
length in bytes of the column character set. On a UTF8 attachment a
VARCHAR(15) column in NONE or a single-byte character set got 15 bytes, i.e.
3 characters, and isc_array_get_slice/put_slice failed with string right
truncation. Use the declared number of characters in the attachment
character set when it's longer, as DSQL does for messages.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VARCHAR ARRAY of UTF8 Charset fails [CORE3765]

1 participant