Menu

#8 Bug in supplied binary b64 with windows stdin

v1.0 (example)
open
nobody
None
5
2023-09-02
2023-02-22
No

The supplied b64.exe does not work properly under Windows 10 cmd.exe if echo is used to pipe standard input. It does work properly under windows 10 if the input is put into a file and the file is fed to the program.

For example create the textfile using Notepad named "test.txt" containing the line

THISisSOURCEdata

Note the following output:

C:\Users\tedm\Downloads\b64.0.94>notepad test.txt

C:\Users\tedm\Downloads\b64.0.94>b64 -e test.txt
VEhJU2lzU09VUkNFZGF0YQ==

C:\Users\tedm\Downloads\b64.0.94>echo THISisSOURCEdata | b64 -e
VEhJU2lzU09VUkNFZGF0YSAK

C:\Users\tedm\Downloads\b64.0.94>

Now, shorten the line to

THISisSOURCEdat

Note the output:

C:\Users\tedm\Downloads\b64.0.94>b64 -e test.txt
VEhJU2lzU09VUkNFZGF0

C:\Users\tedm\Downloads\b64.0.94>echo THISisSOURCEdat | b64 -e
VEhJU2lzU09VUkNFZGF0IAo=

C:\Users\tedm\Downloads\b64.0.94>

Now shorten it by one more character and note the output:

C:\Users\tedm\Downloads\b64.0.94>b64 -e test.txt
VEhJU2lzU09VUkNFZGE=

C:\Users\tedm\Downloads\b64.0.94>echo THISisSOURCEda | b64 -e
VEhJU2lzU09VUkNFZGEgCg==

C:\Users\tedm\Downloads\b64.0.94>

Possibly a recompile using one of the suggestions in the "reviews" would help I have not tried. Just beware using the binary in scripts, etc. under Windows.

Discussion

  • Ted Mittelstaedt

    Note that decoding -d does appear to work properly using stdin under windows.

     
  • Bob Trower

    Bob Trower - 2023-09-02

    Note:I had started this quite a while ago and my ADHD brain neglected to actually press Post. Sorry about that.
    Thank you so much for reporting this. I looked into it further, and there is indeed an issue with piping sometimes with these binaries. The bug is somewhere in the tcc compiler that I use in order to create small binaries. I opted to release the binary as I did because these binaries from tinycc are tiny. It passed the following test (just tested this):
    b64 | b64 -e | b64 -d
    Above displays the syntax box after encoding to base64 and decoding back to source.
    The issue with piping in the tcc compiler does not exist with the gcc compiler. I am working on a huge body of project code and niggles with the tcc code are bothersome, but I want to keep whatever I release small. As you no doubt know yourself, this is increasingly challenging.
    Anyway, you have my respect and heartfelt thanks for taking the time and trouble to not just report the problem but to test and demonstrate the issue.
    I will be returning to clean this up with commentary because the code is now used in hundreds of millions of devices all over the world. The code was reflective of my style, philosophy, and tool suite at the time I published this over twenty years ago. Since that time I have continued to refine my thinking and tools have matured, so an update seems appropriate.

     

Log in to post a comment.