Skip to content

Conversation

@arthurbdiniz
Copy link

@arthurbdiniz arthurbdiniz commented Nov 15, 2024

The bug arises from the use of generic integer types (int) in test cases involving large numerical values that exceed the range of a 32-bit integer.

In Go, the size of the int type depends on the platform, this behavior causes inconsistencies when handling large integers, such as -9223372036854775808 and 9007199254740993.

On 32-bit systems, these values cannot be represented correctly as int, leading to potential overflow or truncation errors. By explicitly using the int64 type in the affected test cases, the code ensures proper handling and representation of large integers across all platforms, avoiding platform-specific bugs and improving the reliability of the tests.

Reproduce

Run tests setting GOARCH to 386.

GOARCH=386 GOOS=linux go test -vet=off -v -p 2 sigs.k8s.io/yaml sigs.k8s.io/yaml/goyaml.v2 sigs.k8s.io/yaml/goyaml.v3


# sigs.k8s.io/yaml/goyaml.v2_test [sigs.k8s.io/yaml/goyaml.v2.test]
goyaml.v2/decode_test.go:134:33: cannot use -9223372036854775808 (untyped int constant) as int value in map literal (overflows)
# sigs.k8s.io/yaml [sigs.k8s.io/yaml.test]
./yaml_test.go:186:50: cannot use math.MaxInt64 (untyped int constant 9223372036854775807) as int value in argument to fmt.Sprintf (overflows)
./yaml_test.go:415:16: cannot use 9007199254740993 (untyped int constant) as int value in struct literal (overflows)
FAIL	sigs.k8s.io/yaml [build failed]
FAIL	sigs.k8s.io/yaml/goyaml.v2 [build failed]
# sigs.k8s.io/yaml/goyaml.v3_test [sigs.k8s.io/yaml/goyaml.v3.test]
goyaml.v3/decode_test.go:180:33: cannot use -9223372036854775808 (untyped int constant) as int value in map literal (overflows)
FAIL	sigs.k8s.io/yaml/goyaml.v3 [build failed]
FAIL

Changes:

  • Switched expected values from map[string]interface{} to map[string]int64
    to ensure type consistency and avoid type mismatch failures in DeepEquals.
  • Ensured literal -9223372036854775808 is treated safely as an int64 to
    prevent compile-time constant overflow on 32-bit platforms.
  • Updated Marshal and Unmarshal tests to explicitly use int64 when working
    with large integer constants that exceed int32 range.

These changes address potential issues with integer overflow and ensure compatibility across platforms with differing integer size representations.

@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Nov 15, 2024
@k8s-ci-robot k8s-ci-robot requested review from dims and sttts November 15, 2024 17:08
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Nov 15, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: arthurbdiniz / name: Arthur Diniz (909bfc4)

@k8s-ci-robot
Copy link

Welcome @arthurbdiniz!

It looks like this is your first PR to kubernetes-sigs/yaml 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/yaml has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Nov 15, 2024
Copy link
Author

@arthurbdiniz arthurbdiniz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an amended commit to my fork and for some reason it was not synced here.

master...arthurbdiniz:yaml:fix/tests-32bit-architectures

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 19, 2025
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle rotten
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Mar 21, 2025
@arthurbdiniz
Copy link
Author

/remove-lifecycle rotten

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Mar 22, 2025
@BenTheElder
Copy link
Member

/cc @liggitt @dims

@k8s-ci-robot k8s-ci-robot requested a review from liggitt April 2, 2025 21:55
@BenTheElder
Copy link
Member

NOTE: the upstream https://github.com/go-yaml/yaml was archived april 1st 2025 (yes april first ... https://github.com/go-yaml/yaml#this-project-is-unmaintained)

So we don't have much reason to worry about reconciling diffs with upstream.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 2, 2025
@liggitt
Copy link

liggitt commented Apr 3, 2025

/approve

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 3, 2025
@arthurbdiniz
Copy link
Author

Added an amended commit to my fork and for some reason it was not synced here.

master...arthurbdiniz:yaml:fix/tests-32bit-architectures

As peer this message for some reason the changes on my forked branch did not sync automatically. So I had sync it.

Sorry for dropping the approval.

@liggitt liggitt added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Apr 3, 2025
@ccoVeille
Copy link

ccoVeille commented Sep 22, 2025

The "bug" occurs on yaml/go-yaml too

GOARCH=386 go test ./...
# go.yaml.in/yaml/v4_test [go.yaml.in/yaml/v4.test]
./decode_test.go:247:25: cannot use -9223372036854775808 (untyped int constant) as int value in map literal (overflows)

So I opened

@dims
Copy link
Member

dims commented Sep 22, 2025

@ccoVeille
Copy link

I feel like this comment was for @arthurbdiniz

He owns the current PR.

@ingydotnet
Copy link

ingydotnet commented Sep 29, 2025

@arthurbdiniz would you mind opening a PR at https://github.com/yaml/go-yaml/pulls
That repo is now the upstream for this repo and https://github.com/kubernetes/kubernetes/
Target the main branch and we can talk about it also going into v3 and v2.
If you don't have time, say so, and we can grab it ourselves.

Apologies. Misunderstood.

@ccoVeille has opened this as yaml/go-yaml#129

@arthurbdiniz arthurbdiniz force-pushed the fix/tests-32bit-architectures branch from 53ce8bb to a90de8f Compare September 29, 2025 21:17
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 29, 2025
@arthurbdiniz arthurbdiniz force-pushed the fix/tests-32bit-architectures branch from a90de8f to ef34267 Compare September 29, 2025 21:38
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 29, 2025
@arthurbdiniz
Copy link
Author

I think instead of changing the interface to int64 it's possible to create a function to return the correct int size.

func intOrInt64(v int64) interface{} {
	// On 64-bit systems, large numbers will be int
	// On 32-bit systems, they will remain int64
	if strconv.IntSize == 64 {
		return int(v)
	}
	return v
}

Here is the reference for the full patch.

0001-Fix-int64-minimum-value-handling-in-tests-for-cross-.patch

Now that goyaml.v2 and goyaml.v3 folders are just a reference to go.yaml.in/yaml/* that function can be incorporated at yaml/go-yaml#129 if make sense.

cc @ccoVeille

@arthurbdiniz
Copy link
Author

Some yaml_test.go test are still failing so I updated this PR to fix that.

@ccoVeille
Copy link

I think instead of changing the interface to int64 it's possible to create a function to return the correct int size.

func intOrInt64(v int64) interface{} {
	// On 64-bit systems, large numbers will be int
	// On 32-bit systems, they will remain int64
	if strconv.IntSize == 64 {
		return int(v)
	}
	return v
}

Here is the reference for the full patch.

0001-Fix-int64-minimum-value-handling-in-tests-for-cross-.patch

Now that goyaml.v2 and goyaml.v3 folders are just a reference to go.yaml.in/yaml/* that function can be incorporated at yaml/go-yaml#129 if make sense.

cc @ccoVeille

I'm hesitant with this.

I would prefer a type that is defined by arch with build tags, but it would be overkill. Your solution works, but honestly I'm unsure there is a need for it.

Your solution to use int64 everywhere sounds a sane and simpler approach.

So I'm fine with it.

@arthurbdiniz arthurbdiniz requested a review from liggitt October 1, 2025 18:27
Update test cases with overflow errors on 32-bit (i386) architectures.

Signed-off-by: Arthur Diniz <[email protected]>
@arthurbdiniz arthurbdiniz force-pushed the fix/tests-32bit-architectures branch from ef34267 to 909bfc4 Compare October 9, 2025 21:50
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 9, 2025
@arthurbdiniz arthurbdiniz requested a review from liggitt October 9, 2025 21:50
Copy link

@liggitt liggitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 10, 2025
@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: arthurbdiniz, ccoVeille, liggitt

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 10, 2025
@k8s-ci-robot k8s-ci-robot merged commit 537896d into kubernetes-sigs:master Oct 10, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants