mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +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
26f7e4b33d
commit
c28138f3fa
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>
|
2011-11-04 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/NSDate.m: ([-timeIntervalSinceDate:]) return NaN if other
|
* Source/NSDate.m: ([-timeIntervalSinceDate:]) return NaN if other
|
||||||
|
|
|
@ -4201,22 +4201,26 @@ appendString(NSMutableData *m, NSUInteger offset, NSUInteger fold,
|
||||||
{
|
{
|
||||||
c = 63;
|
c = 63;
|
||||||
}
|
}
|
||||||
|
else if (c == '_')
|
||||||
|
{
|
||||||
|
c = 63; /* RFC 4648 permits '_' in URLs and filenames */
|
||||||
|
}
|
||||||
else if (c == '+')
|
else if (c == '+')
|
||||||
{
|
{
|
||||||
c = 62;
|
c = 62;
|
||||||
}
|
}
|
||||||
|
else if (c == '-')
|
||||||
|
{
|
||||||
|
c = 62; /* RFC 4648 permits '-' in URLs and filenames */
|
||||||
|
}
|
||||||
else if (c == '=')
|
else if (c == '=')
|
||||||
{
|
{
|
||||||
c = -1;
|
c = -1;
|
||||||
pad++;
|
pad++;
|
||||||
}
|
}
|
||||||
else if (c == '-')
|
|
||||||
{
|
|
||||||
break; /* end */
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
c = -1; /* ignore */
|
c = -1; /* Ignore ... non-standard but more tolerant */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c >= 0)
|
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)
|
if (pos > 0)
|
||||||
{
|
{
|
||||||
NSUInteger i;
|
NSUInteger i;
|
||||||
|
|
|
@ -65,11 +65,22 @@ exact(GSMimeParser **parserPointer, NSData *data)
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||||
|
NSData *cr;
|
||||||
NSData *data;
|
NSData *data;
|
||||||
GSMimeParser *parser;
|
GSMimeParser *parser;
|
||||||
GSMimeDocument *doc;
|
GSMimeDocument *doc;
|
||||||
GSMimeDocument *idoc;
|
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"];
|
data = [NSData dataWithContentsOfFile: @"mime1.dat"];
|
||||||
idoc = exact(0, data);
|
idoc = exact(0, data);
|
||||||
PASS_EQUAL([[[idoc content] objectAtIndex:0] content], @"a",
|
PASS_EQUAL([[[idoc content] objectAtIndex:0] content], @"a",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue