mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 08:41:03 +00:00
[NSData initWithBase64EncodedString]
: Fix decoding of an empty string
Don't call `NSZoneRealloc` with a length of 0, but free the zone and return an empty `NSData` buffer instead.
This commit is contained in:
parent
1cb6ef8572
commit
081f890be8
2 changed files with 13 additions and 0 deletions
|
@ -804,6 +804,13 @@ failure:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
length = dst - result;
|
length = dst - result;
|
||||||
|
|
||||||
|
if (length == 0)
|
||||||
|
{
|
||||||
|
NSZoneFree(zone, result);
|
||||||
|
return [self initWithBytesNoCopy: 0 length: 0 freeWhenDone: YES];
|
||||||
|
}
|
||||||
|
|
||||||
if (options & NSDataBase64DecodingIgnoreUnknownCharacters)
|
if (options & NSDataBase64DecodingIgnoreUnknownCharacters)
|
||||||
{
|
{
|
||||||
/* If the decoded length is a lot shorter than expected (because we
|
/* If the decoded length is a lot shorter than expected (because we
|
||||||
|
|
|
@ -127,6 +127,12 @@ int main()
|
||||||
PASS_EQUAL(data, ref, "base64 decoding Yml0bWFya2V0cyB1c2VyIGluZGVudGl0eQ==")
|
PASS_EQUAL(data, ref, "base64 decoding Yml0bWFya2V0cyB1c2VyIGluZGVudGl0eQ==")
|
||||||
[data release];
|
[data release];
|
||||||
|
|
||||||
|
data = [[NSData alloc] initWithBase64EncodedString: @"\n"
|
||||||
|
options: NSDataBase64DecodingIgnoreUnknownCharacters];
|
||||||
|
ref = [NSData dataWithBytes: "" length: 0];
|
||||||
|
PASS_EQUAL(data, ref, "base64 decoding empty string")
|
||||||
|
[data release];
|
||||||
|
|
||||||
[arp release]; arp = nil;
|
[arp release]; arp = nil;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue