mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-28 11:31:53 +01:00
#4320: Integer overflow in Poco::UTF32Encoding
This commit is contained in:
@@ -69,6 +69,15 @@ public:
|
|||||||
int queryConvert(const unsigned char* bytes, int length) const;
|
int queryConvert(const unsigned char* bytes, int length) const;
|
||||||
int sequenceLength(const unsigned char* bytes, int length) const;
|
int sequenceLength(const unsigned char* bytes, int length) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static int safeToInt(Poco::UInt32 value)
|
||||||
|
{
|
||||||
|
if (value <= 0x10FFFF)
|
||||||
|
return static_cast<int>(value);
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _flipBytes;
|
bool _flipBytes;
|
||||||
static const char* _names[];
|
static const char* _names[];
|
||||||
|
|||||||
@@ -30,22 +30,22 @@ const char* UTF32Encoding::_names[] =
|
|||||||
|
|
||||||
const TextEncoding::CharacterMap UTF32Encoding::_charMap =
|
const TextEncoding::CharacterMap UTF32Encoding::_charMap =
|
||||||
{
|
{
|
||||||
/* 00 */ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
|
/* 00 */ -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
|
||||||
/* 10 */ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
|
/* 10 */ -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
|
||||||
/* 20 */ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
|
/* 20 */ -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
|
||||||
/* 30 */ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
|
/* 30 */ -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
|
||||||
/* 40 */ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
|
/* 40 */ -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
|
||||||
/* 50 */ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
|
/* 50 */ -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
|
||||||
/* 60 */ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
|
/* 60 */ -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
|
||||||
/* 70 */ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
|
/* 70 */ -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
|
||||||
/* 80 */ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
|
/* 80 */ -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
|
||||||
/* 90 */ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
|
/* 90 */ -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
|
||||||
/* a0 */ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
|
/* a0 */ -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
|
||||||
/* b0 */ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
|
/* b0 */ -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
|
||||||
/* c0 */ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
|
/* c0 */ -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
|
||||||
/* d0 */ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
|
/* d0 */ -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
|
||||||
/* e0 */ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
|
/* e0 */ -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
|
||||||
/* f0 */ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
|
/* f0 */ -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@ const TextEncoding::CharacterMap& UTF32Encoding::characterMap() const
|
|||||||
int UTF32Encoding::convert(const unsigned char* bytes) const
|
int UTF32Encoding::convert(const unsigned char* bytes) const
|
||||||
{
|
{
|
||||||
UInt32 uc;
|
UInt32 uc;
|
||||||
unsigned char* p = (unsigned char*) &uc;
|
unsigned char* p = reinterpret_cast<unsigned char*>(&uc);
|
||||||
*p++ = *bytes++;
|
*p++ = *bytes++;
|
||||||
*p++ = *bytes++;
|
*p++ = *bytes++;
|
||||||
*p++ = *bytes++;
|
*p++ = *bytes++;
|
||||||
@@ -129,7 +129,7 @@ int UTF32Encoding::convert(const unsigned char* bytes) const
|
|||||||
uc = ByteOrder::flipBytes(uc);
|
uc = ByteOrder::flipBytes(uc);
|
||||||
}
|
}
|
||||||
|
|
||||||
return uc;
|
return safeToInt(uc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -138,7 +138,7 @@ int UTF32Encoding::convert(int ch, unsigned char* bytes, int length) const
|
|||||||
if (bytes && length >= 4)
|
if (bytes && length >= 4)
|
||||||
{
|
{
|
||||||
UInt32 ch1 = _flipBytes ? ByteOrder::flipBytes((UInt32) ch) : (UInt32) ch;
|
UInt32 ch1 = _flipBytes ? ByteOrder::flipBytes((UInt32) ch) : (UInt32) ch;
|
||||||
unsigned char* p = (unsigned char*) &ch1;
|
unsigned char* p = reinterpret_cast<unsigned char*>(&ch1);
|
||||||
*bytes++ = *p++;
|
*bytes++ = *p++;
|
||||||
*bytes++ = *p++;
|
*bytes++ = *p++;
|
||||||
*bytes++ = *p++;
|
*bytes++ = *p++;
|
||||||
@@ -155,7 +155,7 @@ int UTF32Encoding::queryConvert(const unsigned char* bytes, int length) const
|
|||||||
if (length >= 4)
|
if (length >= 4)
|
||||||
{
|
{
|
||||||
UInt32 uc;
|
UInt32 uc;
|
||||||
unsigned char* p = (unsigned char*) &uc;
|
unsigned char* p = reinterpret_cast<unsigned char*>(&uc);
|
||||||
*p++ = *bytes++;
|
*p++ = *bytes++;
|
||||||
*p++ = *bytes++;
|
*p++ = *bytes++;
|
||||||
*p++ = *bytes++;
|
*p++ = *bytes++;
|
||||||
@@ -164,7 +164,7 @@ int UTF32Encoding::queryConvert(const unsigned char* bytes, int length) const
|
|||||||
{
|
{
|
||||||
uc = ByteOrder::flipBytes(uc);
|
uc = ByteOrder::flipBytes(uc);
|
||||||
}
|
}
|
||||||
return uc;
|
ret = safeToInt(uc);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
Reference in New Issue
Block a user