oficina / home Public

Preserve exact typed integers in native signed metadata

Paul Campbell pushed by paul@keymail.dev b166afc44eb607b36861e717d2f40b46c049a980 parent 2ee3f74
2 files changed, +22 −1
  • internal/provisioner/floor_linux.go +1 −1
  • internal/provisioner/floor_linux_test.go +21 −0
diff --git a/internal/provisioner/floor_linux.go b/internal/provisioner/floor_linux.go
index 8892c32..bcf9bb9 100644
--- a/internal/provisioner/floor_linux.go
+++ b/internal/provisioner/floor_linux.go
@@ -56,7 +56,7 @@ func canonicalJSON(v any) ([]byte, error) {
return nil, ErrRefused
}
j := jsontext.Value(b)
- if j.Canonicalize() != nil {
+ if j.Canonicalize(jsontext.CanonicalizeRawInts(false)) != nil {
return nil, ErrRefused
}
return j, nil
diff --git a/internal/provisioner/floor_linux_test.go b/internal/provisioner/floor_linux_test.go
index 60134fa..c0c61e9 100644
--- a/internal/provisioner/floor_linux_test.go
+++ b/internal/provisioner/floor_linux_test.go
@@ -149,3 +149,24 @@ func TestFloorScanSeesDurableRecordBeforeMarkerUpdate(t *testing.T) {
t.Fatal("matching interrupted marker did not resume", e)
}
}
+
+func TestCanonicalMetadataPreservesTypedIntegerPrecision(t *testing.T) {
+ value := struct {
+ Signed int64 `json:"signed"`
+ Unsigned uint64 `json:"unsigned"`
+ }{9223372036854775807, 18446744073709551615}
+ raw, e := canonicalJSON(value)
+ if e != nil {
+ t.Fatal(e)
+ }
+ if string(raw) != `{"signed":9223372036854775807,"unsigned":18446744073709551615}` {
+ t.Fatal("integer precision lost")
+ }
+ var decoded struct {
+ Signed int64 `json:"signed"`
+ Unsigned uint64 `json:"unsigned"`
+ }
+ if closedJSON(raw, &decoded) != nil || decoded != value {
+ t.Fatal("typed integer did not round trip")
+ }
+}