mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
make base64 decoding more tolerant.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@34128 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
43c06d6065
commit
014c5ebc66
3 changed files with 35 additions and 5 deletions
|
@ -1,3 +1,9 @@
|
|||
2011-11-07 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/Additions/GSMime.m: ([+decodeBase64:]) tolerate missing
|
||||
padding and also use of '-' and '_' rather than '+' and '/' as
|
||||
permitted in the "URL and Filename safe" variation given in RFC 4648
|
||||
|
||||
2011-11-04 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSDate.m: ([-timeIntervalSinceDate:]) return NaN if other
|
||||
|
|
|
@ -4201,22 +4201,26 @@ appendString(NSMutableData *m, NSUInteger offset, NSUInteger fold,
|
|||
{
|
||||
c = 63;
|
||||
}
|
||||
else if (c == '_')
|
||||
{
|
||||
c = 63; /* RFC 4648 permits '_' in URLs and filenames */
|
||||
}
|
||||
else if (c == '+')
|
||||
{
|
||||
c = 62;
|
||||
}
|
||||
else if (c == '-')
|
||||
{
|
||||
c = 62; /* RFC 4648 permits '-' in URLs and filenames */
|
||||
}
|
||||
else if (c == '=')
|
||||
{
|
||||
c = -1;
|
||||
pad++;
|
||||
}
|
||||
else if (c == '-')
|
||||
{
|
||||
break; /* end */
|
||||
}
|
||||
else
|
||||
{
|
||||
c = -1; /* ignore */
|
||||
c = -1; /* Ignore ... non-standard but more tolerant */
|
||||
}
|
||||
|
||||
if (c >= 0)
|
||||
|
@ -4231,6 +4235,15 @@ appendString(NSMutableData *m, NSUInteger offset, NSUInteger fold,
|
|||
}
|
||||
}
|
||||
|
||||
/* If length is not a multiple of four, treat it as if the missing
|
||||
* bytes were the '=' characters normally used for padding.
|
||||
* This is not allowed by the basic standards, but permitted in some
|
||||
* variants of 6ase64 encoding, so we should tolerate it.
|
||||
*/
|
||||
if (length % 4 > 0)
|
||||
{
|
||||
pad += (4 - length % 4);
|
||||
}
|
||||
if (pos > 0)
|
||||
{
|
||||
NSUInteger i;
|
||||
|
|
|
@ -65,11 +65,22 @@ exact(GSMimeParser **parserPointer, NSData *data)
|
|||
int main()
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
NSData *cr;
|
||||
NSData *data;
|
||||
GSMimeParser *parser;
|
||||
GSMimeDocument *doc;
|
||||
GSMimeDocument *idoc;
|
||||
|
||||
cr = [NSData dataWithBytes: "\r" length: 1];
|
||||
|
||||
data = [NSData dataWithBytes: "DQ==" length: 4];
|
||||
PASS_EQUAL([GSMimeDocument decodeBase64: data], cr,
|
||||
"decodeBase64 works for padded data");
|
||||
|
||||
data = [NSData dataWithBytes: "DQ" length: 2];
|
||||
PASS_EQUAL([GSMimeDocument decodeBase64: data], cr,
|
||||
"decodeBase64 works for unpadded data");
|
||||
|
||||
data = [NSData dataWithContentsOfFile: @"mime1.dat"];
|
||||
idoc = exact(0, data);
|
||||
PASS_EQUAL([[[idoc content] objectAtIndex:0] content], @"a",
|
||||
|
|
Loading…
Reference in a new issue