Monday, March 23, 2009

V6 DECODE64 not working properly

It turns out that after all these years, V6's built-in DECODE64 and ENCODE64 actually do not work properly with some binary data.

proc COMPARE_BASE64 {} {
set code {2lIU1ZNw5BYvKi79j4L/+GGmjAQK7uiBQG7elDdKZcE=}
set vgn_result [DECODE64 $code]; #VGN built-in function
set tcl_result [::base64::decode $code]; #TclLib tcl-only implementation
return [join [list \\
[BIN2HEX $vgn_result] \\
[BIN2HEX $tcl_result] \\
[string compare $vgn_result $tcl_result ] \\
] "\\r\\n"]
proc BIN2HEX { text } { binary scan $text H* result; return $result }

--- result ----

If you need to encode/decode base64 for use in non-vignette systems make sure you use tcllib's base64.

This was tested on Vignette's V6 but I am sure it's true for Storyserver 4.2 and V5 as well.


  1. As far as I remember the problem is with the character set of Vignette. V's version of base64 will decode into ascii 8-bit strings while the native base64 implementation will decode into Latin-1 Unicode representation.

  2. It's not an encoding problem. It's probably a bug in the implementation of ENCODE64. It's using a very old C code (dated back to tcl 7.6).

  3. You are right the vignette version doesn't even get the right size:
    4 base64 encoded bytes = 3 decoded bytes

    Is it wrong in both directions the same way ? I mean does ENCODE64 [DECODE64 {...}] give the same result as the input?

  4. it's wrong both ways:
    ENCODE64 [DECODE64 $a] always gives $a

  5. Both directions are wrong.ENCODE64 & DECODE64 are
    same the result as input

  6. I think you have to check one more time because this is totally wrong from both direction.


[Due to much spam, comments are now moderated and will be posted after review]