You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by "Alexander Veit (JIRA)" <ji...@apache.org> on 2007/02/01 23:15:05 UTC

[jira] Commented: (WSCOMMONS-101) axiom base64 encoding is incorrect

    [ https://issues.apache.org/jira/browse/WSCOMMONS-101?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12469596 ] 

Alexander Veit commented on WSCOMMONS-101:
------------------------------------------

The following code shows that the correctness of Axiom's Base64 encoding depends on implementations details of the streams involved. "YWE=YWE=" is clearly not a valid Base64 encoding of a four-byte-array. The provided patch solves this issue.


package org.apache.axiom.om.util;


import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.SequenceInputStream;

import junit.framework.TestCase;


public class BadBase64UsageTestCase extends TestCase
{
    public void test() throws Exception
    {
        assertFalse("getText() returns \"YWE=YWE=\"", "YWE=YWE=".equals(getText()));
    }


    // code borrowed from TextImpl / OMTextImpl
    public String getText() throws IOException
    {
        InputStream inStream;
        inStream = this.getInputStream();

        // int x = inStream.available();
        byte[] data;
        StringBuffer text = new StringBuffer();

        do
        {
            data = new byte[3];
            int len;

            while ((len = inStream.read(data)) > 0)
            {
                byte[] temp = new byte[len];
                System.arraycopy(data, 0, temp, 0, len);
                text.append(org.apache.axiom.om.util.Base64.encode(temp));
            }
        }
        while (inStream.available() > 0);

        return text.toString();
    }


    private InputStream getInputStream()
    {
        return new SequenceInputStream(
            new ByteArrayInputStream("aa".getBytes()),
            new ByteArrayInputStream("aa".getBytes()));
    }
}


> axiom base64 encoding is incorrect
> ----------------------------------
>
>                 Key: WSCOMMONS-101
>                 URL: https://issues.apache.org/jira/browse/WSCOMMONS-101
>             Project: WS-Commons
>          Issue Type: Bug
>          Components: AXIOM
>         Environment: axis2 tomcat win32
>            Reporter: stefan stieglitz
>         Assigned To: Thilina Gunarathne
>         Attachments: axiom-patch-02.zip, test.jpg
>
>
> The base64 encoding of axiom seems to be incorrect. It produces filler characters '=' inside the encoded text. Those are only allowed at the end. In result the encoded text can't be decoded by other libraries. The decoder used by axiom can decode his own encoding, for example xerces-c can not.
> Reproduction:
> To reproduce this behavior try to encode any inhomogeneous image lager than 10kb.
> To ease the error analysis a linefeed has been inserted every 76 characters in booth encoded texts. I'm aware that this manipulation makes any
> decoding of the text impossible. (unless the filler characters at the end are recalculated)
> Example for error:
> [..]
> NDpscUkzSTNI8rTTOxeSRuXdiwB/YjZfDHx7erM48M39gkBiDNrjW3h1ZDL5m0W7a/Ppouyvlt5o
> tTMYN0XneX50O+pN8PPHkMssJ8HeJpTDJJEZbXRdQvbaQxuUL295Z289pdwMVJiubWaa3njKyw==  (line 18)
> DLJGyuf8/wA8Y/tE/tBeLL77XrPxY8b6u87tNdm/8Q6rcK825WR0jecqhViSO2cYxgE62mftL/tC
> [..]
> zcYBGSQeoOBg8j6YruYPA9qsqqNoDZULt+8xAAGBnPIxgZ9eMcAHzXY+Fo5BIblHBygTbjpg8kYy
> f8c4z0rK1zwzLGEMSEwwNJKmQOjLg5GNoxjjH1JPGPq+bwfbW8mwkKwxuTByO3IC7RjHHTPOeg==  (line 36)
> [..]
> Expected encoding:
> [..]
> NDpscUkzSTNI8rTTOxeSRuXdiwB/YjZfDHx7erM48M39gkBiDNrjW3h1ZDL5m0W7a/Ppouyvlt5o
> tTMYN0XneX50O+pN8PPHkMssJ8HeJpTDJJEZbXRdQvbaQxuUL295Z289pdwMVJiubWaa3njKywyy  (line 18)
> Rsrn/P8APGP7RP7QXiy++16z8WPG+rvO7TXZv/EOq3CvNuVkdI3nKoVYkjtnGMYBOtpn7S/7Qvh+
> [..]
> ARkkHqDgYPI+mK7mDwParKqjaA2VC7fvMQABgZzyMYGfXjHAB812PhaOQSG5RwcoE246YPJGMn/H
> OM9Kytc8MyxhDEhMMDSSpkDoy4ORjaMY4x9STxj6vm8H21vJsJCsMbkwcjtyAu0Yxx0zznoa5nXd  (line 36)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org