You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sebb <se...@gmail.com> on 2008/06/21 14:19:15 UTC
[CODEC] Base64 decode() handling of invalid encoded data
How should Base64.decode() handle invalid encoded data?
rfc2045 says:
All line breaks or other characters not
found in Table 1 must be ignored by decoding software. In base64
data, characters other than those in Table 1, line breaks, and other
white space probably indicate a transmission error, about which a
warning message or even a message rejection might be appropriate
under some circumstances.
The decode function currently ignores invalid characters, and stops
when it reaches the first pad character. The caller is not informed
of either occurrence.
Just wondering if the are any use cases that need this information?
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [CODEC] Base64 decode() handling of invalid encoded data
Posted by sebb <se...@gmail.com>.
On 14/07/2008, Jochen Wiedmann <jo...@gmail.com> wrote:
> On Mon, Jul 14, 2008 at 5:21 PM, sebb <se...@gmail.com> wrote:
>
> > Just noticed https://issues.apache.org/jira/browse/CODEC-68 which
> > implies that at least one person is expecting to be able to include
> > invalid base64 characters without a problem - in that case, after the
> > PAD characters.
> >
> > So maybe there is a need to preserve compatibility after all.
>
>
> Questionable. I understand the problem in CODEC-68 to be the
> ArrayIndexOutOfBoundsException, which is indeed not what one would
> expect.
Indeed, and the OOB has been fixed.
But the example showed:
'n', 'A', '=', '=', 0x9c
So clearly the poster is expecting this to succeed.
However, that is not a valid message, and would trigger the invalid
character checking - assuming that the code checks that PAD characters
only occur at the end of the message.
I was testing the code to check for this - a test failed, and that led
me to CODEC-68.
> Jochen
>
>
>
> --
> Look, that's why there's rules, understand? So that you think before
> you break 'em.
>
> -- (Terry Pratchett, Thief of Time)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [CODEC] Base64 decode() handling of invalid encoded data
Posted by Jochen Wiedmann <jo...@gmail.com>.
On Mon, Jul 14, 2008 at 5:21 PM, sebb <se...@gmail.com> wrote:
> Just noticed https://issues.apache.org/jira/browse/CODEC-68 which
> implies that at least one person is expecting to be able to include
> invalid base64 characters without a problem - in that case, after the
> PAD characters.
>
> So maybe there is a need to preserve compatibility after all.
Questionable. I understand the problem in CODEC-68 to be the
ArrayIndexOutOfBoundsException, which is indeed not what one would
expect.
Jochen
--
Look, that's why there's rules, understand? So that you think before
you break 'em.
-- (Terry Pratchett, Thief of Time)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [CODEC] Base64 decode() handling of invalid encoded data
Posted by sebb <se...@gmail.com>.
On 14/07/2008, Jochen Wiedmann <jo...@gmail.com> wrote:
> On Mon, Jul 14, 2008 at 3:37 PM, sebb <se...@gmail.com> wrote:
>
> > Should have tried it before posting ...
> >
> > Both IOException and DecoderException are checked, and so this means
> > that the method signature for
> >
> > public static byte[] decodeBase64()
> >
> > would need to change - or the method needs to convert the
> > DecoderException to an unchecked error.
> >
> > Thoughts?
>
>
> In such cases I'd recommend to catch the Exception and convert it into
> an UndeclaredThrowableException. However, I'd also deprecate the
> method and add a successor. I'd discourage things like adding a
> boolean flag that suppresses the exception.
>
>
Just noticed https://issues.apache.org/jira/browse/CODEC-68 which
implies that at least one person is expecting to be able to include
invalid base64 characters without a problem - in that case, after the
PAD characters.
So maybe there is a need to preserve compatibility after all.
Perhaps one way round this would be to add method(s) that enforce validation?
>
> Jochen
>
>
>
> --
> Look, that's why there's rules, understand? So that you think before
> you break 'em.
>
> -- (Terry Pratchett, Thief of Time)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [CODEC] Base64 decode() handling of invalid encoded data
Posted by Jochen Wiedmann <jo...@gmail.com>.
On Mon, Jul 14, 2008 at 3:37 PM, sebb <se...@gmail.com> wrote:
> Should have tried it before posting ...
>
> Both IOException and DecoderException are checked, and so this means
> that the method signature for
>
> public static byte[] decodeBase64()
>
> would need to change - or the method needs to convert the
> DecoderException to an unchecked error.
>
> Thoughts?
In such cases I'd recommend to catch the Exception and convert it into
an UndeclaredThrowableException. However, I'd also deprecate the
method and add a successor. I'd discourage things like adding a
boolean flag that suppresses the exception.
Jochen
--
Look, that's why there's rules, understand? So that you think before
you break 'em.
-- (Terry Pratchett, Thief of Time)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [CODEC] Base64 decode() handling of invalid encoded data
Posted by sebb <se...@gmail.com>.
On 14/07/2008, Jochen Wiedmann <jo...@gmail.com> wrote:
> On Mon, Jul 14, 2008 at 2:24 PM, sebb <se...@gmail.com> wrote:
> > Just looked at this again.
> >
> > Using IOException causes problems, because the interface BinaryDecoder
> > does not declare that as a possible exception.
> >
> > How about using DecoderException instead?
> >
> > Seems just as appropriate to me.
>
>
> Fine with me.
>
Should have tried it before posting ...
Both IOException and DecoderException are checked, and so this means
that the method signature for
public static byte[] decodeBase64()
would need to change - or the method needs to convert the
DecoderException to an unchecked error.
Thoughts?
>
> Jochen
>
> --
> Look, that's why there's rules, understand? So that you think before
> you break 'em.
>
> -- (Terry Pratchett, Thief of Time)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [CODEC] Base64 decode() handling of invalid encoded data
Posted by Jochen Wiedmann <jo...@gmail.com>.
On Mon, Jul 14, 2008 at 2:24 PM, sebb <se...@gmail.com> wrote:
> Just looked at this again.
>
> Using IOException causes problems, because the interface BinaryDecoder
> does not declare that as a possible exception.
>
> How about using DecoderException instead?
>
> Seems just as appropriate to me.
Fine with me.
Jochen
--
Look, that's why there's rules, understand? So that you think before
you break 'em.
-- (Terry Pratchett, Thief of Time)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [CODEC] Base64 decode() handling of invalid encoded data
Posted by sebb <se...@gmail.com>.
Just looked at this again.
Using IOException causes problems, because the interface BinaryDecoder
does not declare that as a possible exception.
How about using DecoderException instead?
Seems just as appropriate to me.
On 25/06/2008, Julius Davies <ju...@gmail.com> wrote:
> +1 for IOException.
>
> I've come around on this. Originally I liked garbage-in, garbage-out
> idea, but I'm +1 to IOException now. The reason I've come around is
> that I just cannot imagine any Java developer who would be confused or
> surprised when presented with an IOException in this situation.
>
> I'll open a ticket and attach a patch by Sunday if it hasn't been done
> by then. It will need some JUnits, too.
>
> yours,
>
> Julius
>
>
>
>
> On Wed, Jun 25, 2008 at 10:39 AM, Jochen Wiedmann
> <jo...@gmail.com> wrote:
> > On Sat, Jun 21, 2008 at 2:19 PM, sebb <se...@gmail.com> wrote:
> >
> >> How should Base64.decode() handle invalid encoded data?
> >
> > I'd vote for an IOException. As the RFC indicates, such characters are
> > more than likely indicators for errors. If anyone requires such a
> > message, it is easy to implement a FilterInputStream, or FilterReader.
> >
> > Jochen
> >
> >
> > --
> > Look, that's why there's rules, understand? So that you think before
> > you break 'em.
> >
> > -- (Terry Pratchett, Thief of Time)
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> > For additional commands, e-mail: dev-help@commons.apache.org
> >
> >
>
>
>
>
> --
> yours,
>
> Julius Davies
> 250-592-2284 (Home)
> 250-893-4579 (Mobile)
> http://juliusdavies.ca/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [CODEC] Base64 decode() handling of invalid encoded data
Posted by Julius Davies <ju...@gmail.com>.
+1 for IOException.
I've come around on this. Originally I liked garbage-in, garbage-out
idea, but I'm +1 to IOException now. The reason I've come around is
that I just cannot imagine any Java developer who would be confused or
surprised when presented with an IOException in this situation.
I'll open a ticket and attach a patch by Sunday if it hasn't been done
by then. It will need some JUnits, too.
yours,
Julius
On Wed, Jun 25, 2008 at 10:39 AM, Jochen Wiedmann
<jo...@gmail.com> wrote:
> On Sat, Jun 21, 2008 at 2:19 PM, sebb <se...@gmail.com> wrote:
>
>> How should Base64.decode() handle invalid encoded data?
>
> I'd vote for an IOException. As the RFC indicates, such characters are
> more than likely indicators for errors. If anyone requires such a
> message, it is easy to implement a FilterInputStream, or FilterReader.
>
> Jochen
>
>
> --
> Look, that's why there's rules, understand? So that you think before
> you break 'em.
>
> -- (Terry Pratchett, Thief of Time)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
--
yours,
Julius Davies
250-592-2284 (Home)
250-893-4579 (Mobile)
http://juliusdavies.ca/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [CODEC] Base64 decode() handling of invalid encoded data
Posted by Jochen Wiedmann <jo...@gmail.com>.
On Sat, Jun 21, 2008 at 2:19 PM, sebb <se...@gmail.com> wrote:
> How should Base64.decode() handle invalid encoded data?
I'd vote for an IOException. As the RFC indicates, such characters are
more than likely indicators for errors. If anyone requires such a
message, it is easy to implement a FilterInputStream, or FilterReader.
Jochen
--
Look, that's why there's rules, understand? So that you think before
you break 'em.
-- (Terry Pratchett, Thief of Time)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org