DaveAKing / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Should HashingOutputStream.write make a copy of the byte[] before passing it to the Hasher? #1586

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
(We're pretty sure the answer is "no, that's too paranoid." I'm filing this 
issue so that we have a record of the discussion.)

"I would say that it's probably paranoid. Additionally, the way I see it, part 
of the reason that HashingOutputStream exists is so that the user doesn't have 
to make such a copy. (That is, he could just write everything to a 
ByteArrayOutputStream, hash the whole thing, and then write the whole thing.) I 
guess that making a paranoid copy isn't quite that bad, since we're only ever 
copying a chunk of the data at once, rather than the whole thing. Still, I do 
think it's paranoia. The caller who chooses to use HashingOutputStream is 
almost certainly the caller who chooses the HashFunction, so any damage he does 
it to himself. We do like to protect against that sort of thing, of course, but 
I doubt there are even many custom HashFunction implementations in existence, 
so a bug seems unlikely."

Original issue reported on code.google.com by cpov...@google.com on 21 Nov 2013 at 3:28

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<issue id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:10

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:08