obscure string bugfixes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@22723 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2006-03-28 06:05:04 +00:00
parent 2fb7a5de95
commit a88c6fbd98
3 changed files with 75 additions and 47 deletions

View file

@ -1,3 +1,9 @@
2006-03-28 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSString.m: Fix error initialising mutable string from
unicode char array conmtaining ascii characters.
Fix a few memory mleaks.
2006-03-25 Richard Frith-Macdonald <rfm@gnu.org> 2006-03-25 Richard Frith-Macdonald <rfm@gnu.org>
* Source/win32/NSStreamWin32.m: Various tidyups for pipe streams. * Source/win32/NSStreamWin32.m: Various tidyups for pipe streams.
@ -5,7 +11,7 @@
* Headers/Additions/GNUstepBase/Unicode.h: Add validation function. * Headers/Additions/GNUstepBase/Unicode.h: Add validation function.
* Source/Additions/Unicode.m: Add unicode validation function and * Source/Additions/Unicode.m: Add unicode validation function and
alter UTF8 handling to be stricter. alter UTF8 handling to be stricter.
* Source/GSString.m: validate unicode when initialisiung a string. * Source/GSString.m: validate unicode when initialising a string.
Also create 8bit data strings rather than 16bit where possible. Also create 8bit data strings rather than 16bit where possible.
2006-03-24 Richard Frith-Macdonald <rfm@gnu.org> 2006-03-24 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -1349,19 +1349,11 @@ GSToUnicode(unichar **dst, unsigned int *size, const unsigned char *src,
} }
u = u & ~(0xffffffff << ((5 * sle) + 1)); u = u & ~(0xffffffff << ((5 * sle) + 1));
spos += sle; spos += sle;
}
else
{
spos++;
}
/* /*
* Add codepoint as either a single unichar for BMP * We discard invalid codepoints here.
* or as a pair of surrogates for codepoints over 16 bits.
* We also discard invalid codepoints here.
*/ */
if (u > 0x10ffff || u == 0xfffe || u == 0xffff
if (u == 0xfffe || u == 0xffff
|| (u >= 0xfdd0 && u <= 0xfdef)) || (u >= 0xfdd0 && u <= 0xfdef))
{ {
result = NO; // Invalid character. result = NO; // Invalid character.
@ -1373,18 +1365,21 @@ GSToUnicode(unichar **dst, unsigned int *size, const unsigned char *src,
result = NO; // Unmatched half of surrogate pair. result = NO; // Unmatched half of surrogate pair.
break; break;
} }
if (u > 0x10ffff)
{
result = NO; // Too large
break;
} }
else
{
spos++;
}
/*
* Add codepoint as either a single unichar for BMP
* or as a pair of surrogates for codepoints over 16 bits.
*/
if (dpos >= bsize) if (dpos >= bsize)
{ {
GROW(); GROW();
} }
if (u < 0x10000) if (u < 0x10000)
{ {
ptr[dpos++] = u; ptr[dpos++] = u;

View file

@ -402,6 +402,10 @@ setup(void)
if (GSUnicode(chars, length, &isASCII, &isLatin1) != length) if (GSUnicode(chars, length, &isASCII, &isLatin1) != length)
{ {
if (flag == YES && chars != 0)
{
NSZoneFree(NSZoneFromPointer(chars), chars);
}
return nil; // Invalid data return nil; // Invalid data
} }
if (isASCII == YES if (isASCII == YES
@ -420,6 +424,10 @@ setup(void)
{ {
me->_contents.c[length] = (unsigned char)chars[length]; me->_contents.c[length] = (unsigned char)chars[length];
} }
if (flag == YES && chars != 0)
{
NSZoneFree(NSZoneFromPointer(chars), chars);
}
} }
else else
{ {
@ -3093,6 +3101,10 @@ agree, create a new GSUnicodeInlineString otherwise.
if (GSUnicode(chars, length, &isASCII, &isLatin1) != length) if (GSUnicode(chars, length, &isASCII, &isLatin1) != length)
{ {
RELEASE(self); RELEASE(self);
if (flag == YES && chars != 0)
{
NSZoneFree(NSZoneFromPointer(chars), chars);
}
return nil; // Invalid data return nil; // Invalid data
} }
if (isASCII == YES if (isASCII == YES
@ -3114,6 +3126,10 @@ agree, create a new GSUnicodeInlineString otherwise.
me->_contents.c[length] = (unsigned char)chars[length]; me->_contents.c[length] = (unsigned char)chars[length];
} }
RELEASE(self); RELEASE(self);
if (flag == YES && chars != 0)
{
NSZoneFree(NSZoneFromPointer(chars), chars);
}
return (id)me; return (id)me;
} }
if (_contents.u != 0) if (_contents.u != 0)
@ -3559,29 +3575,39 @@ agree, create a new GSUnicodeInlineString otherwise.
if (GSUnicode(chars, length, &isASCII, &isLatin1) != length) if (GSUnicode(chars, length, &isASCII, &isLatin1) != length)
{ {
RELEASE(self); RELEASE(self);
if (flag == YES && chars != 0)
{
NSZoneFree(NSZoneFromPointer(chars), chars);
}
return nil; // Invalid data return nil; // Invalid data
} }
if (isASCII == YES if (isASCII == YES
|| (intEnc == NSISOLatin1StringEncoding && isLatin1 == YES)) || (intEnc == NSISOLatin1StringEncoding && isLatin1 == YES))
{ {
GSStr me; unsigned char *buf;
/* #if GS_WITH_GC
* OK ... we can do a more compact version _zone = GSAtomicMallocZone();
*/ #else
me = (GSStr)NSAllocateObject(GSCInlineStringClass, length, _zone = NSDefaultMallocZone();
GSObjCZone(self)); #endif
me->_contents.c = (unsigned char*)&((GSCInlineString*)me)[1]; buf = NSZoneMalloc(_zone, length);
me->_count = length; _count = length;
me->_flags.wide = 0; _capacity = length;
me->_flags.free = 1; _contents.c = buf;
_flags.wide = 0;
_flags.free = 1;
while (length-- > 0) while (length-- > 0)
{ {
me->_contents.c[length] = (unsigned char)chars[length]; buf[length] = (unsigned char)chars[length];
} }
RELEASE(self); if (flag == YES && chars != 0)
return (id)me; {
NSZoneFree(NSZoneFromPointer(chars), chars);
} }
}
else
{
_count = length; _count = length;
_capacity = length; _capacity = length;
_contents.u = chars; _contents.u = chars;
@ -3599,6 +3625,7 @@ agree, create a new GSUnicodeInlineString otherwise.
{ {
_zone = 0; _zone = 0;
} }
}
return self; return self;
} }