-
Notifications
You must be signed in to change notification settings - Fork 18k
encoding/asn1: ObjectIdentifier Unmarshal error if SubOID > MaxInt32 on 64bit machine too #71679
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
Comments
Line 322 in 30f5158
// Ensure that the returned value fits in an int on all platforms
if ret64 > math.MaxInt32 {
err = StructuralError{"base 128 integer too large"}
} I find this check is what is limiting the The following patch resolves the issue diff --git a/src/encoding/asn1/asn1.go b/src/encoding/asn1/asn1.go
index 488fb9b1e0..42d4e69b94 100644
--- a/src/encoding/asn1/asn1.go
+++ b/src/encoding/asn1/asn1.go
@@ -319,7 +319,7 @@ func parseBase128Int(bytes []byte, initOffset int) (ret, offset int, err error)
if b&0x80 == 0 {
ret = int(ret64)
// Ensure that the returned value fits in an int on all platforms
- if ret64 > math.MaxInt32 {
+ if ret64 > math.MaxInt {
err = StructuralError{"base 128 integer too large"}
}
return This will not resolve the issue for 32-bit architecture. But |
CC @golang/security. |
We limit Unmarshal to 32 bit OID components so that we get consistent behavior across platforms, as such I don't expect we will change this to support larger components only on systems with 64 bit integers. Perhaps we should make Marshal fail just so we have parity, but that would be a breaking change. Really, if you care about larger OIDs with large components, you should use the crypto/x509.OID type, which was explicitly designed to solve this problem. |
Thank you for the info on Got your point. But there seems to be a catch here, in go ecosystem I have found And for documenting unxpected behavior, I think we have two options:
|
Go version
go version go1.24.0 darwin/amd64
Output of
go env
in your module/workspace:What did you do?
On a 64-bit machine, I tried to
Marshal
and thenUnmarshal
theasn1.ObjectIdentifier
with all SubOIDs <= MaxInt32 and some SubOIDs > MaxInt32 separatelyhttps://go.dev/play/p/4CDcLlS1LLm
What did you see happen?
For ObjectIdentifier with SubOIDs <= MaxInt32, Marshal and Unmarshal both works without any error.
But, for ObjectIdentifier with some SubOIDs > MaxInt32,
Mashal
works without any error butUnmarshal
throws an error.OUTPUT:
What did you expect to see?
Marshal
works, soUnmarshal
should also work.EXPECTED OUTPUT:
The text was updated successfully, but these errors were encountered: