-
Notifications
You must be signed in to change notification settings - Fork 63
algorithm: Deprecate ErrDigestInvalidLength #35
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
algorithm: Deprecate ErrDigestInvalidLength #35
Conversation
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>
b297dcc to
1167650
Compare
|
I agree that throwing 2 different errors with similar meaning is not the way to go. Clients who are interested in these values would then have to check 2 separate values, although likely when they were created separately it was assumed that clients would not be switching off invalid data (not actionable) and just propagating the error or discarding the value. A better solution involves wrapping such as |
|
On Fri, Jun 09, 2017 at 02:59:29PM -0700, Derek McGowan wrote:
A better solution involves wrapping such as `github.com/pkg/errors`,
but we are not going to pull in a vendor to this package.
I don't think that's a better solution, because anchoredEncodedRegexps
is checking both the character validity and length at the same time
[1]. Why would you even *want* two errors to distinguish between
invalid characters and invalid lengths, even if we had a way to wrap
them together for easier catching?
The best thing we can probably do now is just close this PR and
revisit it if `pkg/errors` is upstreamed into golang or when we add
support for other encodings and need logic smarter than `.Size() *
2` to determine the expected size.
But we already check the length via the regexp [2]. Why do it twice?
The current way adds a redundant (hex-assuming) size check to valid
digests, and the only upside is a possibly-cheaper rejection (vs. the
regexp check) for invalid-length encoded portions of the wrong length.
I haven't benchmarked either the size check or the regexp check, and I
don't know what fraction of production use encoded portions have
invalid lengths, but if most of your encoded portions are valid, this
PR will make validation faster by one size check with no downside.
… but it is not worth reducing the error granularity…
I agree with the portions that I've replaced with ellipses, but why is
it not worth reducing error granularity if clients are not acting on
the distinction?
[1]: https://github.com/opencontainers/go-digest/blob/279bed98673dd5bef374d3b6e4b09e2af76183bf/algorithm.go#L55-L61
[2]: https://github.com/opencontainers/go-digest/blob/279bed98673dd5bef374d3b6e4b09e2af76183bf/algorithm.go#L188
|
|
@wking Length and format errors are fundamentally different. This PR is fairly naive. |
Maybe in some cases. For example,
So to find potential effects due to these murky cases, let's look for some consumers distinguishing between the two cases: Going through those:
So of the docker/distribution cases, one is a wrapping validation framework that defines its own So is there anywhere that this distinction matters? The only downstream effect I can see for this consolidation is that it would be improved errors in the docker/distribution API. Are there any consumers that would be negatively impacted by this change? |
|
@wking The problem with this PR is that it removes the size check. That is not required to deprecate the length error. |
This error was added in 9721254 (Validate digest length on parsing, 2015-12-02) and motivated with:
That doesn't make sense to me, because
Digest.ValidatereturnsErrDigestUnsupportedwhen 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 placeErrDigestInvalidLengthcould matter). From the other changes in distribution/distribution#1231, 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 PR removes that assumption. Thesha256and other hex-based algorithms are still getting their lengths validated viaanchoredEncodedRegexps.This PR is based on my earlier suggestion. I think @AkihiroSuda kept the error because of @stevvooe's comment:
but with this PR we will continue throwing an error in the invalid-length case and folks who are switching on
ErrDigestInvalidLengthcan continue to do so. It's just that they'll no longer be able to distinguish betweenErrDigestInvalidLengthandErrDigestInvalidFormat, and since I see no reason to do that, I don't see it as an important backwards-compat concern. If someone does have a reason to make that distinction, pointing at that code would be a good reason to close this PR.