-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Validate digest length on parsing #1231
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
Conversation
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
|
This assumes that digests have fixed size output. Do we want to force this on all future hash implementations? Are there any variable length hashes that we may want to support in the future? I think the answer is yes, all digest implementations have a fixed size hash output. |
|
I think it's reasonable to assume a fixed hash size. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this break tarsum?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tarsum has its own parse method so isn't affected(not better or worse). I can try to fix tarsum as well if needed, of course.
|
@stevvooe If there is ever a case where fix length doesn't work, |
|
@tonistiigi I think we're okay. SHA3, blake etc. all have fixed length output. As a matter of security, this is probably more than okay to enforce. LGTM |
|
LGTM |
Validate digest length on parsing
This error was added in 9721254 (Validate digest length on parsing, 2015-12-02) and motivated with [1]: > The new error is mostly so that digest.Set doesn't need a special > way to figure out if invalid digest had a algorithm prefix or not. That doesn't make sense to me, because Digest.Validate returns ErrDigestUnsupported when there is no algorithm prefix (I've added a test to confirm this as well), and that seems orthogonal to encoding validation (which is the only place ErrDigestInvalidLength could matter). From the other changes in [1], I think the issue was just that invalid lengths weren't raising errors at all. I see no reason to distinguish between invalid lengths, invalid characters, and other invalid-encoded-portion errors, so this commit collapses the error into ErrDigestInvalidFormat. [1]: distribution/distribution#1231 Signed-off-by: W. Trevor King <wking@tremily.us>
This error was added in 9721254 (Validate digest length on parsing, 2015-12-02) and motivated with [1]: > The new error is mostly so that digest.Set doesn't need a special > way to figure out if invalid digest had a algorithm prefix or not. That doesn't make sense to me, because Digest.Validate returns ErrDigestUnsupported when there is no algorithm prefix (I've added a test to confirm this as well), and that seems orthogonal to encoding validation (which is the only place ErrDigestInvalidLength could matter). From the other changes in [1], I think the issue was just that invalid lengths weren't raising errors at all. I see no reason to distinguish between invalid lengths, invalid characters, and other invalid-encoded-portion errors, so this commit collapses the error into ErrDigestInvalidFormat. The code I'm removing assumed hex (with '.Size() * 2'), so this commit removes that assumption. The sha256 and other hex-based algorithms are still getting their lengths validated via anchoredEncodedRegexps. [1]: distribution/distribution#1231 Signed-off-by: W. Trevor King <wking@tremily.us>
Validate digest length on parsing
Validate digest length on parsing
@aaronlehmann @dmcgowan
The new error is mostly so that
digest.Setdoesn't need a special way to figure out if invalid digest had a algorithm prefix or not.Signed-off-by: Tonis Tiigi tonistiigi@gmail.com