Project

General

Profile

Actions

Bug #10696

closed

Digest implementation on Windows faulty

Added by Apophis (Thomas Bruderer) over 7 years ago. Updated over 7 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
Target version:
-
ruby -v:
ruby 2.1.5p273 (2014-11-13 revision 48405) [i386-mingw32]
[ruby-core:67332]

Description

The example I made with SHA1, but the same happens for other digests, so it seems to affect the generic implementation of the interface and not the specific hash implementations.

Digest::SHA1.hexdigest(File.read('test.file'))
"069171eeda5f9c72cb28cb8d3fb7bbfad57ef044"

Digest::SHA1.file('test.file').hexdigest
"8b797e38c097eb8eab5c9d061ba241b03c6e739e"

The correct hash (independently checked) is the one in the file method. The Problem seems to be coming from the Read of this binary "string".

To me it seems like it could be a Problem with the character Encoding in a string. I first thought it was stopping at the null character but a test with valid ASCII with a NULL Character in the middle did actually work correctly. I attached the test-file to reproduce this beahvior. It is a very simple File with a few non-printable Characters including NULL.

This is a very specific Problem only happening on Windows. I report it for the last Version I tested, but I also tested this on 1.9 build with the same result. The same test runs fine on Linux.


Files

test.file (32 Bytes) test.file Apophis (Thomas Bruderer), 01/04/2015 06:57 PM

Updated by jeremyevans0 (Jeremy Evans) over 7 years ago

This is probably a line ending issue, with ASCII CR getting removed by File.read on Windows. You need to read the file in binary mode to get correct results on Windows:

Digest::SHA1.hexdigest(File.binread('test.file'))

Updated by nobu (Nobuyoshi Nakada) over 7 years ago

  • Status changed from Open to Rejected

Updated by Apophis (Thomas Bruderer) over 7 years ago

Yes works correclty.

Sorry for the unnecessary Bugreport. At least it is documented now.

Actions

Also available in: Atom PDF