You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Lorenzo Ingrillì (JIRA)" <ji...@apache.org> on 2009/12/03 17:55:23 UTC

[jira] Created: (CODEC-94) unexpected CRLF at end of base64 encoded string

unexpected CRLF at end of base64 encoded string
-----------------------------------------------

                 Key: CODEC-94
                 URL: https://issues.apache.org/jira/browse/CODEC-94
             Project: Commons Codec
          Issue Type: Bug
    Affects Versions: 1.4
         Environment: java 1.6u17
ubuntu linux 9.10
            Reporter: Lorenzo Ingrillì


Sometimes, a base64 encoded string ends inappropriately with \r\n characters.

In the example below, i used value 64 as line lenght and the generated base64 string lenght was 44; nevertheless string ends with CRLF .

(i think, this bug is not related to bug #CODEC-89)

How to reproduce:

public class Test {
	public static void main(String args[]) throws Exception {

		byte[] input = new byte[] {
				25, 109, -39, -23, 82, -47, -88, 115, 
				-34, 126, -57, 16, -110, -110, 60, -7, 
				-123, -3, 60, 91, 112, -93, -67, -65, -71,
				-107, 123, -15, -106, 86, -80, 79
		};

		Base64 b64 = new Base64(64);
		String output = new String(b64.encode(input));

		System.out.println("*"+output+"*");
	}
}

the output was: GW3Z6VLRqHPefscQkpI8+YX9PFtwo72/uZV78ZZWsE8=\r\n


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


[jira] Commented: (CODEC-94) unexpected CRLF at end of base64 encoded string

Posted by "Lorenzo Ingrillì (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CODEC-94?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12785630#action_12785630 ] 

Lorenzo Ingrillì commented on CODEC-94:
---------------------------------------

Static method Base64.encodeBase64() seems work correctly, so now i'm using it instead the instance method encode()

this code work as expected:

{code:title=Test2.java}
import org.apache.commons.codec.binary.Base64;

public class Test2 {
	public static void main(String args[]) throws Exception {

		byte[] input = new byte[] {
				25, 109, -39, -23, 82, -47, -88, 115, 
				-34, 126, -57, 16, -110, -110, 60, -7, 
				-123, -3, 60, 91, 112, -93, -67, -65, -71,
				-107, 123, -15, -106, 86, -80, 79
		};

		// wrong behaviour:
		// Base64 b64 = new Base64(64);
		// String output = new String(b64.encode(input));

		// correct behaviour:
		String output = new String(Base64.encodeBase64(input));
		
		System.out.println("*"+output+"*");
	}
}
{code}

> unexpected CRLF at end of base64 encoded string
> -----------------------------------------------
>
>                 Key: CODEC-94
>                 URL: https://issues.apache.org/jira/browse/CODEC-94
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>         Environment: java 1.6u17
> ubuntu linux 9.10
>            Reporter: Lorenzo Ingrillì
>
> Sometimes, a base64 encoded string ends inappropriately with \r\n characters.
> In the example below, i used value 64 as line lenght and the generated base64 string lenght was 44; nevertheless string ends with CRLF .
> (i think, this bug is not related to bug #CODEC-89)
> How to reproduce:
> {code:title=Test.java|borderStyle=solid}
> public class Test {
> 	public static void main(String args[]) throws Exception {
> 		byte[] input = new byte[] {
> 				25, 109, -39, -23, 82, -47, -88, 115, 
> 				-34, 126, -57, 16, -110, -110, 60, -7, 
> 				-123, -3, 60, 91, 112, -93, -67, -65, -71,
> 				-107, 123, -15, -106, 86, -80, 79
> 		};
> 		Base64 b64 = new Base64(64);
> 		String output = new String(b64.encode(input));
> 		System.out.println("*"+output+"*");
> 	}
> }
> {code}
> the output was: GW3Z6VLRqHPefscQkpI8+YX9PFtwo72/uZV78ZZWsE8=\r\n

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


[jira] Commented: (CODEC-94) unexpected CRLF at end of base64 encoded string

Posted by "Julius Davies (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CODEC-94?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12850435#action_12850435 ] 

Julius Davies commented on CODEC-94:
------------------------------------



This is not a dup of CODEC-89.  Notice this line in Lorenzo's original example:

Base64 b64 = new Base64(64);

That '64' is a request for chunked output (in 64 character lines).  The user is complaining that output with less than 64 characters should not end in CRLF, but as I showed in my Dec 3rd 2009 comment appending a final CRLF in chunked mode is the original commons-codec-1.3.jar behaviour.

Since commons-codec-1.3.jar has been appending a final CRLF in chunked mode for almost six years without anyone complaining (until now), I think we should leave it this way.  Users should run the output through String.trim() if they don't like this.




> unexpected CRLF at end of base64 encoded string
> -----------------------------------------------
>
>                 Key: CODEC-94
>                 URL: https://issues.apache.org/jira/browse/CODEC-94
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>         Environment: java 1.6u17
> ubuntu linux 9.10
>            Reporter: Lorenzo Ingrillì
>
> Sometimes, a base64 encoded string ends inappropriately with \r\n characters.
> In the example below, i used value 64 as line lenght and the generated base64 string lenght was 44; nevertheless string ends with CRLF .
> (i think, this bug is not related to bug #CODEC-89)
> How to reproduce:
> {code:title=Test.java|borderStyle=solid}
> public class Test {
> 	public static void main(String args[]) throws Exception {
> 		byte[] input = new byte[] {
> 				25, 109, -39, -23, 82, -47, -88, 115, 
> 				-34, 126, -57, 16, -110, -110, 60, -7, 
> 				-123, -3, 60, 91, 112, -93, -67, -65, -71,
> 				-107, 123, -15, -106, 86, -80, 79
> 		};
> 		Base64 b64 = new Base64(64);
> 		String output = new String(b64.encode(input));
> 		System.out.println("*"+output+"*");
> 	}
> }
> {code}
> the output was: GW3Z6VLRqHPefscQkpI8+YX9PFtwo72/uZV78ZZWsE8=\r\n

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


[jira] Updated: (CODEC-94) unexpected CRLF at end of base64 encoded string

Posted by "Lorenzo Ingrillì (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CODEC-94?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Lorenzo Ingrillì updated CODEC-94:
----------------------------------

    Description: 
Sometimes, a base64 encoded string ends inappropriately with \r\n characters.

In the example below, i used value 64 as line lenght and the generated base64 string lenght was 44; nevertheless string ends with CRLF .

(i think, this bug is not related to bug #CODEC-89)

How to reproduce:

{code:title=Test.java|borderStyle=solid}
public class Test {
	public static void main(String args[]) throws Exception {

		byte[] input = new byte[] {
				25, 109, -39, -23, 82, -47, -88, 115, 
				-34, 126, -57, 16, -110, -110, 60, -7, 
				-123, -3, 60, 91, 112, -93, -67, -65, -71,
				-107, 123, -15, -106, 86, -80, 79
		};

		Base64 b64 = new Base64(64);
		String output = new String(b64.encode(input));

		System.out.println("*"+output+"*");
	}
}
{code}

the output was: GW3Z6VLRqHPefscQkpI8+YX9PFtwo72/uZV78ZZWsE8=\r\n


  was:
Sometimes, a base64 encoded string ends inappropriately with \r\n characters.

In the example below, i used value 64 as line lenght and the generated base64 string lenght was 44; nevertheless string ends with CRLF .

(i think, this bug is not related to bug #CODEC-89)

How to reproduce:

public class Test {
	public static void main(String args[]) throws Exception {

		byte[] input = new byte[] {
				25, 109, -39, -23, 82, -47, -88, 115, 
				-34, 126, -57, 16, -110, -110, 60, -7, 
				-123, -3, 60, 91, 112, -93, -67, -65, -71,
				-107, 123, -15, -106, 86, -80, 79
		};

		Base64 b64 = new Base64(64);
		String output = new String(b64.encode(input));

		System.out.println("*"+output+"*");
	}
}

the output was: GW3Z6VLRqHPefscQkpI8+YX9PFtwo72/uZV78ZZWsE8=\r\n



> unexpected CRLF at end of base64 encoded string
> -----------------------------------------------
>
>                 Key: CODEC-94
>                 URL: https://issues.apache.org/jira/browse/CODEC-94
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>         Environment: java 1.6u17
> ubuntu linux 9.10
>            Reporter: Lorenzo Ingrillì
>
> Sometimes, a base64 encoded string ends inappropriately with \r\n characters.
> In the example below, i used value 64 as line lenght and the generated base64 string lenght was 44; nevertheless string ends with CRLF .
> (i think, this bug is not related to bug #CODEC-89)
> How to reproduce:
> {code:title=Test.java|borderStyle=solid}
> public class Test {
> 	public static void main(String args[]) throws Exception {
> 		byte[] input = new byte[] {
> 				25, 109, -39, -23, 82, -47, -88, 115, 
> 				-34, 126, -57, 16, -110, -110, 60, -7, 
> 				-123, -3, 60, 91, 112, -93, -67, -65, -71,
> 				-107, 123, -15, -106, 86, -80, 79
> 		};
> 		Base64 b64 = new Base64(64);
> 		String output = new String(b64.encode(input));
> 		System.out.println("*"+output+"*");
> 	}
> }
> {code}
> the output was: GW3Z6VLRqHPefscQkpI8+YX9PFtwo72/uZV78ZZWsE8=\r\n

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


[jira] Commented: (CODEC-94) unexpected CRLF at end of base64 encoded string

Posted by "Julius Davies (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CODEC-94?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12785557#action_12785557 ] 

Julius Davies commented on CODEC-94:
------------------------------------

Just making sure this isn't a regression.  Here's what I found:

- The only way to chunk the encoding in commons-codec-1.3 is via this static method:

{code}
// 76 character chunking is hard-coded.
// 64 character chunking is not possible!
Base64.encodeBase64Chunked( byte[] data );
{code}


- commons-codec-1.3 appends a final CRLF no matter what when using "chunked" mode:

[YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
]

[YWFhYWFhYWFhYQ==
]

[YQ==
]



Question for Lorenzo:  how would you feel about just calling new String().trim() yourself?

A direct byte[] trim is also possible.  Involves some System.arraycopy().  Maybe commons-codec could even offer up such a method ( bytesTrim() ).




> unexpected CRLF at end of base64 encoded string
> -----------------------------------------------
>
>                 Key: CODEC-94
>                 URL: https://issues.apache.org/jira/browse/CODEC-94
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>         Environment: java 1.6u17
> ubuntu linux 9.10
>            Reporter: Lorenzo Ingrillì
>
> Sometimes, a base64 encoded string ends inappropriately with \r\n characters.
> In the example below, i used value 64 as line lenght and the generated base64 string lenght was 44; nevertheless string ends with CRLF .
> (i think, this bug is not related to bug #CODEC-89)
> How to reproduce:
> {code:title=Test.java|borderStyle=solid}
> public class Test {
> 	public static void main(String args[]) throws Exception {
> 		byte[] input = new byte[] {
> 				25, 109, -39, -23, 82, -47, -88, 115, 
> 				-34, 126, -57, 16, -110, -110, 60, -7, 
> 				-123, -3, 60, 91, 112, -93, -67, -65, -71,
> 				-107, 123, -15, -106, 86, -80, 79
> 		};
> 		Base64 b64 = new Base64(64);
> 		String output = new String(b64.encode(input));
> 		System.out.println("*"+output+"*");
> 	}
> }
> {code}
> the output was: GW3Z6VLRqHPefscQkpI8+YX9PFtwo72/uZV78ZZWsE8=\r\n

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


[jira] Issue Comment Edited: (CODEC-94) unexpected CRLF at end of base64 encoded string

Posted by "Nikolas Falco (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CODEC-94?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12804470#action_12804470 ] 

Nikolas Falco edited comment on CODEC-94 at 1/25/10 9:52 AM:
-------------------------------------------------------------

is a dupe of CODEC-89 bug.
input is chunked also if input length is less than a chunk size.

using "Base64.encodeBase64(input)" work because by API is explicit "Encodes binary data using the base64 algorithm but does not chunk the output."

But "Base64.encodeBase64(input)" work correctly if the input never exceed 64 byte, for a long input should be add line separator as do "new Base64(64)"?

      was (Author: nfalco79):
    is a dupe of CODEC-89 bug.
input is chunked also if input length is less than a chunk size.

using Base64.encodeBase64(input) work because by API is explicit "Encodes binary data using the base64 algorithm but does not chunk the output."
  
> unexpected CRLF at end of base64 encoded string
> -----------------------------------------------
>
>                 Key: CODEC-94
>                 URL: https://issues.apache.org/jira/browse/CODEC-94
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>         Environment: java 1.6u17
> ubuntu linux 9.10
>            Reporter: Lorenzo Ingrillì
>
> Sometimes, a base64 encoded string ends inappropriately with \r\n characters.
> In the example below, i used value 64 as line lenght and the generated base64 string lenght was 44; nevertheless string ends with CRLF .
> (i think, this bug is not related to bug #CODEC-89)
> How to reproduce:
> {code:title=Test.java|borderStyle=solid}
> public class Test {
> 	public static void main(String args[]) throws Exception {
> 		byte[] input = new byte[] {
> 				25, 109, -39, -23, 82, -47, -88, 115, 
> 				-34, 126, -57, 16, -110, -110, 60, -7, 
> 				-123, -3, 60, 91, 112, -93, -67, -65, -71,
> 				-107, 123, -15, -106, 86, -80, 79
> 		};
> 		Base64 b64 = new Base64(64);
> 		String output = new String(b64.encode(input));
> 		System.out.println("*"+output+"*");
> 	}
> }
> {code}
> the output was: GW3Z6VLRqHPefscQkpI8+YX9PFtwo72/uZV78ZZWsE8=\r\n

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


[jira] Commented: (CODEC-94) unexpected CRLF at end of base64 encoded string

Posted by "Nikolas Falco (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CODEC-94?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12804470#action_12804470 ] 

Nikolas Falco commented on CODEC-94:
------------------------------------

is a dupe of CODEC-89 bug.
input is chunked also if input length is less than a chunk size.

using Base64.encodeBase64(input) work because by API is explicit "Encodes binary data using the base64 algorithm but does not chunk the output."

> unexpected CRLF at end of base64 encoded string
> -----------------------------------------------
>
>                 Key: CODEC-94
>                 URL: https://issues.apache.org/jira/browse/CODEC-94
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>         Environment: java 1.6u17
> ubuntu linux 9.10
>            Reporter: Lorenzo Ingrillì
>
> Sometimes, a base64 encoded string ends inappropriately with \r\n characters.
> In the example below, i used value 64 as line lenght and the generated base64 string lenght was 44; nevertheless string ends with CRLF .
> (i think, this bug is not related to bug #CODEC-89)
> How to reproduce:
> {code:title=Test.java|borderStyle=solid}
> public class Test {
> 	public static void main(String args[]) throws Exception {
> 		byte[] input = new byte[] {
> 				25, 109, -39, -23, 82, -47, -88, 115, 
> 				-34, 126, -57, 16, -110, -110, 60, -7, 
> 				-123, -3, 60, 91, 112, -93, -67, -65, -71,
> 				-107, 123, -15, -106, 86, -80, 79
> 		};
> 		Base64 b64 = new Base64(64);
> 		String output = new String(b64.encode(input));
> 		System.out.println("*"+output+"*");
> 	}
> }
> {code}
> the output was: GW3Z6VLRqHPefscQkpI8+YX9PFtwo72/uZV78ZZWsE8=\r\n

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


[jira] Commented: (CODEC-94) unexpected CRLF at end of base64 encoded string

Posted by "Julius Davies (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CODEC-94?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12785558#action_12785558 ] 

Julius Davies commented on CODEC-94:
------------------------------------

ps.  Julius Davies is very relieved that this isn't yet another regression!  Whew!  Yay for commons-codec-1.3 appending CRLF !

> unexpected CRLF at end of base64 encoded string
> -----------------------------------------------
>
>                 Key: CODEC-94
>                 URL: https://issues.apache.org/jira/browse/CODEC-94
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>         Environment: java 1.6u17
> ubuntu linux 9.10
>            Reporter: Lorenzo Ingrillì
>
> Sometimes, a base64 encoded string ends inappropriately with \r\n characters.
> In the example below, i used value 64 as line lenght and the generated base64 string lenght was 44; nevertheless string ends with CRLF .
> (i think, this bug is not related to bug #CODEC-89)
> How to reproduce:
> {code:title=Test.java|borderStyle=solid}
> public class Test {
> 	public static void main(String args[]) throws Exception {
> 		byte[] input = new byte[] {
> 				25, 109, -39, -23, 82, -47, -88, 115, 
> 				-34, 126, -57, 16, -110, -110, 60, -7, 
> 				-123, -3, 60, 91, 112, -93, -67, -65, -71,
> 				-107, 123, -15, -106, 86, -80, 79
> 		};
> 		Base64 b64 = new Base64(64);
> 		String output = new String(b64.encode(input));
> 		System.out.println("*"+output+"*");
> 	}
> }
> {code}
> the output was: GW3Z6VLRqHPefscQkpI8+YX9PFtwo72/uZV78ZZWsE8=\r\n

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


[jira] Commented: (CODEC-94) unexpected CRLF at end of base64 encoded string

Posted by "Gary Gregory (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CODEC-94?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12850467#action_12850467 ] 

Gary Gregory commented on CODEC-94:
-----------------------------------

I added to the class Base64Test new test methods called testRfc4648* based on RFC 4648 that show our inconsistent handling of CR LF at the end of data. Failing assertions are //commented out.

> unexpected CRLF at end of base64 encoded string
> -----------------------------------------------
>
>                 Key: CODEC-94
>                 URL: https://issues.apache.org/jira/browse/CODEC-94
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>         Environment: java 1.6u17
> ubuntu linux 9.10
>            Reporter: Lorenzo Ingrillì
>
> Sometimes, a base64 encoded string ends inappropriately with \r\n characters.
> In the example below, i used value 64 as line lenght and the generated base64 string lenght was 44; nevertheless string ends with CRLF .
> (i think, this bug is not related to bug #CODEC-89)
> How to reproduce:
> {code:title=Test.java|borderStyle=solid}
> public class Test {
> 	public static void main(String args[]) throws Exception {
> 		byte[] input = new byte[] {
> 				25, 109, -39, -23, 82, -47, -88, 115, 
> 				-34, 126, -57, 16, -110, -110, 60, -7, 
> 				-123, -3, 60, 91, 112, -93, -67, -65, -71,
> 				-107, 123, -15, -106, 86, -80, 79
> 		};
> 		Base64 b64 = new Base64(64);
> 		String output = new String(b64.encode(input));
> 		System.out.println("*"+output+"*");
> 	}
> }
> {code}
> the output was: GW3Z6VLRqHPefscQkpI8+YX9PFtwo72/uZV78ZZWsE8=\r\n

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


[jira] Issue Comment Edited: (CODEC-94) unexpected CRLF at end of base64 encoded string

Posted by "Gary Gregory (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CODEC-94?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12850467#action_12850467 ] 

Gary Gregory edited comment on CODEC-94 at 3/27/10 3:49 AM:
------------------------------------------------------------

I added to the class Base64Test new test methods called testRfc4648* based on RFC 4648 that show our inconsistent handling of CR LF at the end of data. Failing assertions are //commented out.

I'll have to rethink some of these tests since CR LF after = is fine but not OK in the "middle" of data since CR LF is not in the alphabet. 

We should define and document what the behavior is for non-alphabet chars.

      was (Author: ggregory@seagullsw.com):
    I added to the class Base64Test new test methods called testRfc4648* based on RFC 4648 that show our inconsistent handling of CR LF at the end of data. Failing assertions are //commented out.
  
> unexpected CRLF at end of base64 encoded string
> -----------------------------------------------
>
>                 Key: CODEC-94
>                 URL: https://issues.apache.org/jira/browse/CODEC-94
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>         Environment: java 1.6u17
> ubuntu linux 9.10
>            Reporter: Lorenzo Ingrillì
>
> Sometimes, a base64 encoded string ends inappropriately with \r\n characters.
> In the example below, i used value 64 as line lenght and the generated base64 string lenght was 44; nevertheless string ends with CRLF .
> (i think, this bug is not related to bug #CODEC-89)
> How to reproduce:
> {code:title=Test.java|borderStyle=solid}
> public class Test {
> 	public static void main(String args[]) throws Exception {
> 		byte[] input = new byte[] {
> 				25, 109, -39, -23, 82, -47, -88, 115, 
> 				-34, 126, -57, 16, -110, -110, 60, -7, 
> 				-123, -3, 60, 91, 112, -93, -67, -65, -71,
> 				-107, 123, -15, -106, 86, -80, 79
> 		};
> 		Base64 b64 = new Base64(64);
> 		String output = new String(b64.encode(input));
> 		System.out.println("*"+output+"*");
> 	}
> }
> {code}
> the output was: GW3Z6VLRqHPefscQkpI8+YX9PFtwo72/uZV78ZZWsE8=\r\n

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