Skip to content

Generating hashes of strings can cause inconsistent results. #2

@mfreidel

Description

@mfreidel

Description

This does not affect the consistency of file hashes!

Differences in line endings on Windows and Unix-like systems cause inconsistent results from b3sum when it is given a string as input from the pipeline. This may be more of an issue with b3sum than with B3-PSUtils, but the module utilizes this feature.

The module's current use of key derivation mode based on string input and future plans of implementing keyed mode would not produce results that are consistent across platforms.

To Reproduce

In a Windows PowerShell Session:

PS C:\...> Get-B3StringHash "test"
c0058b2f040246a1cb3b274204f179562db2fbe0bb97fececbe95839e3acc7e7
PS C:\...> "test" | & $HOME\.cargo\bin\b3sum.exe
c0058b2f040246a1cb3b274204f179562db2fbe0bb97fececbe95839e3acc7e7
PS C:\...> cmd /c "echo test|$HOME\.cargo\bin\b3sum.exe"
c0058b2f040246a1cb3b274204f179562db2fbe0bb97fececbe95839e3acc7e7

On a Linux system:

PS /home/user> "test" | & ~/.cargo/bin/b3sum
dea2b412aa90f1b43a06ca5e8b8feafec45ae1357971322749480f4e1572eaa2
PS /home/user> bash -c 'echo "test" | ~/.cargo/bin/b3sum'
dea2b412aa90f1b43a06ca5e8b8feafec45ae1357971322749480f4e1572eaa2

Expected behavior

(Misconception?) Strings passed through pipeline didn't include line endings.

Versions

  • Module Version: 0.2.1+
  • PowerShell Version: Any. Tested using: (5.1 Windows Desktop), (6.2.4 Windows Core), and (6.2.4 Linux Core)
  • Pester Version: N/A
  • b3sum Version: 0.1.4

Additional context

Cross-platform support is a future goal of the module.

On Linux, adding a return carriage character to the end will produce the same as Windows output:

user@host~$ echo -e "test\r" | ~/.cargo/bin/b3sum 
c0058b2f040246a1cb3b274204f179562db2fbe0bb97fececbe95839e3acc7e7

The same In Linux PowerShell:

PS /home/user> "test`r" | & ~/.cargo/bin/b3sum
c0058b2f040246a1cb3b274204f179562db2fbe0bb97fececbe95839e3acc7e7
PS /home/user> bash -c "echo -e `"test`r`" | ~/.cargo/bin/b3sum" 
c0058b2f040246a1cb3b274204f179562db2fbe0bb97fececbe95839e3acc7e7

On Windows, especially inside PowerShell, there does not appear to be a way to omit the return carriage from the new line and get a Linux-like result

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions