On Tue, Feb 27, 2007 at 09:20:56AM +0000, Brian Candler
wrote:
> irb(main):001:0> RUBY_VERSION
> => "1.8.5"
> irb(main):002:0> a = "b2s="
> => "b2s="
> irb(main):003:0> b = "xefxbbxbf" + a
> => "357273277b2s="
> irb(main):004:0> a.unpack("m")
> => ["ok"]
> irb(main):005:0> b.unpack("m")
> => ["$ 00e332"]
>
> That is, non-printable characters (here a UTF8-encoded
BOM) are causing MIME
> unpack to return garbage.
I had a quick look in pack.c in 1.8.6-preview2. I think the
problem is here:
char *s;
...
if ((a = b64_xtable[(int)s[0]]) == -1)
break;
if ((b = b64_xtable[(int)s[1]]) == -1)
break;
if ((c = b64_xtable[(int)s[2]]) == -1)
break;
if ((d = b64_xtable[(int)s[3]]) == -1)
break;
A negative signed char will still be negative after casting
to int, as can
be demonstrated like this:
---- 8< ----------------------------------------
#include <stdio.h>
int main(void)
{
char *s = "xff";
printf("%dn", (int)s[0]); /* prints -1 */
return 0;
}
---- 8< ----------------------------------------
So I think those entries need to be changed to
b64_xtable[((unsigned char *)s)[0]] ... etc
Regards,
Brian.
|