From 2421e7077362f73731bf982ca939822abcf2fc8d Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Fri, 13 Sep 2024 09:27:07 -0700 Subject: [PATCH] Ignore a couple of new gosec lints --- mmdbtype/types.go | 1 + mmdbtype/types_test.go | 2 ++ tree.go | 10 +++++++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/mmdbtype/types.go b/mmdbtype/types.go index d14ae6d..ac8fe1c 100644 --- a/mmdbtype/types.go +++ b/mmdbtype/types.go @@ -215,6 +215,7 @@ func (t Int32) Equal(other DataType) bool { } func (t Int32) size() int { + //nolint:gosec // this is correct. return 4 - bits.LeadingZeros32(uint32(t))/8 } diff --git a/mmdbtype/types_test.go b/mmdbtype/types_test.go index 47502d2..2c5824e 100644 --- a/mmdbtype/types_test.go +++ b/mmdbtype/types_test.go @@ -211,6 +211,8 @@ func TestUint128(t *testing.T) { } for i := 1; i <= bits/8; i++ { expected := &big.Int{} + + //nolint:gosec // i is positive. expected.Lsh(big.NewInt(1), 8*uint(i)) expected = expected.Sub(expected, big.NewInt(1)) input := hex.EncodeToString([]byte{byte(i)}) + ctrlByte + strings.Repeat("ff", i) diff --git a/tree.go b/tree.go index 62bfac6..ac10596 100644 --- a/tree.go +++ b/tree.go @@ -656,9 +656,13 @@ func (t *Tree) writeMetadata(dw *dataWriter) (int64, error) { metadata := mmdbtype.Map{ "binary_format_major_version": mmdbtype.Uint16(2), "binary_format_minor_version": mmdbtype.Uint16(0), - "build_epoch": mmdbtype.Uint64(t.buildEpoch), - "database_type": mmdbtype.String(t.databaseType), - "description": description, + + // Although it might make sense to change the type on this, there is no use + // case where someone would reasonably pass a negative build epoch. + //nolint:gosec // See above. + "build_epoch": mmdbtype.Uint64(t.buildEpoch), + "database_type": mmdbtype.String(t.databaseType), + "description": description, //nolint:gosec // no risk. Will be 4 or 6. "ip_version": mmdbtype.Uint16(t.ipVersion), "languages": languages,