Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getSourceString is not uniquely decodable #53

Closed
fitzn opened this issue Sep 12, 2017 · 2 comments
Closed

getSourceString is not uniquely decodable #53

fitzn opened this issue Sep 12, 2017 · 2 comments

Comments

@fitzn
Copy link
Contributor

fitzn commented Sep 12, 2017

(Feel free to resolve this as Won't Fix based on the limited set of potential strings that can be keys in a Unit dictionary. This is merely proof-of-concept for something that struck me as weird.)

The object_hash module uses the getSourceString function to turn a Unit into a String before hashing the String to produce a content_hash (among other things). The getSourceString function produces the same output String for different inputs, which, in turn, produces an identical hash. This is because the object type is not tokenized, and this could theoretically cause an issue as it breaks the widespread assumption that different inputs of the same data type (e.g., Unit) will hash to different values.

This example input:

var objectOne = ['s', 'a'];
var sourceStringOne = getSourceString(objectOne);

var objectTwo = [{s: {s: 'a'}}];
var sourceStringTwo = getSourceString(objectTwo);

console.log("Object One: " + sourceStringOne);
console.log("Object Two: " + sourceStringTwo);
console.log("Strings match? " + (sourceStringOne === sourceStringTwo));

produces this output (including unprintable characters):

Object One: [�s�s�s�a�]
Object Two: [�s�s�s�a�]
Strings match? true

Again, this case is extremely unlikely (maybe impossible) in this code base since the Unit object's keys are fixed, but I figured I'd call it out.

@tonyofbyteball
Copy link
Member

you're right that should have been avoided but the fixed structure of unit and other objects saves us.

@fitzn
Copy link
Contributor Author

fitzn commented Sep 23, 2017

@tonyofbyteball Okay, resolving this for now then.

@fitzn fitzn closed this as completed Sep 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants