mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-22 21:23:04 +01:00
Remove hability to overflow declared character length in legacy multibyte charsets.
This commit is contained in:
parent
244d996035
commit
24df7c3d9c
@ -275,8 +275,9 @@ typedef void (*pfn_INTL_cs_destroy) (
|
||||
#define CHARSET_VERSION_1 1
|
||||
|
||||
/* charset flag values */
|
||||
#define CHARSET_LEGACY_SEMANTICS 1 /* MBCS strings may overflow declared lengths
|
||||
in characters (but not in bytes) */
|
||||
|
||||
/* MBCS strings may overflow declared lengths in characters (but not in bytes) */
|
||||
/* Removed from FB 4 - #define CHARSET_LEGACY_SEMANTICS 1 */
|
||||
|
||||
#define CHARSET_ASCII_BASED 2 /* Value of ASCII characters is equal to the
|
||||
ASCII character set */
|
||||
|
@ -33,7 +33,7 @@ CHARSET_ENTRY(CS_big_5)
|
||||
|
||||
csptr->charset_version = CHARSET_VERSION_1;
|
||||
csptr->charset_name = POSIX;
|
||||
csptr->charset_flags |= CHARSET_LEGACY_SEMANTICS | CHARSET_ASCII_BASED;
|
||||
csptr->charset_flags |= CHARSET_ASCII_BASED;
|
||||
csptr->charset_min_bytes_per_char = 1;
|
||||
csptr->charset_max_bytes_per_char = 2;
|
||||
csptr->charset_space_length = 1;
|
||||
|
@ -33,7 +33,7 @@ CHARSET_ENTRY(CS_gb_2312)
|
||||
|
||||
csptr->charset_version = CHARSET_VERSION_1;
|
||||
csptr->charset_name = POSIX;
|
||||
csptr->charset_flags |= CHARSET_LEGACY_SEMANTICS | CHARSET_ASCII_BASED;
|
||||
csptr->charset_flags |= CHARSET_ASCII_BASED;
|
||||
csptr->charset_min_bytes_per_char = 1;
|
||||
csptr->charset_max_bytes_per_char = 2;
|
||||
csptr->charset_space_length = 1;
|
||||
|
@ -56,7 +56,6 @@ CHARSET_ENTRY(CS_sjis)
|
||||
{
|
||||
CS_jis_0208_1990(csptr, NULL); //, cs_name); Second param is unused
|
||||
csptr->charset_name = "SJIS";
|
||||
csptr->charset_flags |= CHARSET_LEGACY_SEMANTICS;
|
||||
csptr->charset_min_bytes_per_char = 1;
|
||||
csptr->charset_space_length = 1;
|
||||
csptr->charset_space_character = (const BYTE*) " "; // 0x20
|
||||
@ -71,7 +70,6 @@ CHARSET_ENTRY(CS_euc_j)
|
||||
{
|
||||
CS_jis_0208_1990(csptr, NULL); //cs_name); Second param is unused
|
||||
csptr->charset_name = "EUC-J";
|
||||
csptr->charset_flags |= CHARSET_LEGACY_SEMANTICS;
|
||||
csptr->charset_min_bytes_per_char = 1;
|
||||
csptr->charset_space_length = 1;
|
||||
csptr->charset_space_character = (const BYTE*) " "; // 0x20
|
||||
|
@ -34,7 +34,7 @@ CHARSET_ENTRY(CS_ksc_5601)
|
||||
|
||||
csptr->charset_version = CHARSET_VERSION_1;
|
||||
csptr->charset_name = "KSC_5601";
|
||||
csptr->charset_flags |= CHARSET_LEGACY_SEMANTICS | CHARSET_ASCII_BASED;
|
||||
csptr->charset_flags |= CHARSET_ASCII_BASED;
|
||||
csptr->charset_min_bytes_per_char = 1;
|
||||
csptr->charset_max_bytes_per_char = 2;
|
||||
csptr->charset_space_length = 1;
|
||||
|
@ -32,7 +32,7 @@ CHARSET_ENTRY(CS_unicode_fss)
|
||||
{
|
||||
csptr->charset_version = CHARSET_VERSION_1;
|
||||
csptr->charset_name = "UNICODE_FSS";
|
||||
csptr->charset_flags |= CHARSET_LEGACY_SEMANTICS | CHARSET_ASCII_BASED;
|
||||
csptr->charset_flags |= CHARSET_ASCII_BASED;
|
||||
csptr->charset_min_bytes_per_char = 1;
|
||||
csptr->charset_max_bytes_per_char = 3;
|
||||
csptr->charset_space_length = 1;
|
||||
|
@ -419,9 +419,7 @@ void EngineCallbacks::validateData(CharSet* toCharSet, SLONG length, const UCHAR
|
||||
void EngineCallbacks::validateLength(CharSet* toCharSet, SLONG toLength, const UCHAR* start,
|
||||
const USHORT to_size)
|
||||
{
|
||||
if (toCharSet &&
|
||||
toCharSet->isMultiByte() &&
|
||||
!(toCharSet->getFlags() & CHARSET_LEGACY_SEMANTICS))
|
||||
if (toCharSet && toCharSet->isMultiByte())
|
||||
{
|
||||
Jrd::thread_db* tdbb = NULL;
|
||||
SET_TDBB(tdbb);
|
||||
|
@ -547,32 +547,9 @@ void INTL_adjust_text_descriptor(thread_db* tdbb, dsc* desc)
|
||||
{
|
||||
Firebird::HalfStaticArray<UCHAR, BUFFER_SMALL> buffer;
|
||||
|
||||
if (charSet->getFlags() & CHARSET_LEGACY_SEMANTICS)
|
||||
{
|
||||
desc->dsc_length = charSet->substring(TEXT_LEN(desc), desc->dsc_address, TEXT_LEN(desc),
|
||||
buffer.getBuffer(TEXT_LEN(desc) * charSet->maxBytesPerChar()), 0,
|
||||
TEXT_LEN(desc));
|
||||
|
||||
const ULONG maxLength = TEXT_LEN(desc) / charSet->maxBytesPerChar();
|
||||
ULONG charLength = charSet->length(desc->dsc_length, desc->dsc_address, true);
|
||||
|
||||
while (charLength > maxLength)
|
||||
{
|
||||
if (desc->dsc_address[desc->dsc_length - 1] == *charSet->getSpace())
|
||||
{
|
||||
--desc->dsc_length;
|
||||
--charLength;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
desc->dsc_length = charSet->substring(TEXT_LEN(desc), desc->dsc_address,
|
||||
TEXT_LEN(desc), buffer.getBuffer(TEXT_LEN(desc)), 0,
|
||||
TEXT_LEN(desc) / charSet->maxBytesPerChar());
|
||||
}
|
||||
desc->dsc_length = charSet->substring(TEXT_LEN(desc), desc->dsc_address,
|
||||
TEXT_LEN(desc), buffer.getBuffer(TEXT_LEN(desc)), 0,
|
||||
TEXT_LEN(desc) / charSet->maxBytesPerChar());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -951,9 +928,7 @@ int INTL_convert_string(dsc* to, const dsc* from, ErrorFunction err)
|
||||
const ULONG src_len = toCharSet->length(toLength, start, false);
|
||||
const ULONG dest_len = (ULONG) to_size / toCharSet->maxBytesPerChar();
|
||||
|
||||
if (toCharSet->isMultiByte() &&
|
||||
!(toCharSet->getFlags() & CHARSET_LEGACY_SEMANTICS) &&
|
||||
src_len > dest_len)
|
||||
if (toCharSet->isMultiByte() && src_len > dest_len)
|
||||
{
|
||||
err(Arg::Gds(isc_arith_except) << Arg::Gds(isc_string_truncation) <<
|
||||
Arg::Gds(isc_trunc_limits) << Arg::Num(dest_len) << Arg::Num(src_len));
|
||||
|
@ -1459,7 +1459,6 @@ static INTL_BOOL cs_unicode_fss_init(charset* csptr,
|
||||
|
||||
IntlUtil::initNarrowCharset(csptr, "UNICODE_FSS");
|
||||
csptr->charset_max_bytes_per_char = 3;
|
||||
csptr->charset_flags |= CHARSET_LEGACY_SEMANTICS;
|
||||
|
||||
IntlUtil::initConvert(&csptr->charset_to_unicode, internal_fss_to_unicode);
|
||||
IntlUtil::initConvert(&csptr->charset_from_unicode, internal_unicode_to_fss);
|
||||
|
Loading…
Reference in New Issue
Block a user