Skip to content

Fix int64 minimum value handling in tests for cross-architecture compatibility#129

Merged
ingydotnet merged 3 commits intoyaml:mainfrom
ccoVeille:i386
Dec 21, 2025
Merged

Fix int64 minimum value handling in tests for cross-architecture compatibility#129
ingydotnet merged 3 commits intoyaml:mainfrom
ccoVeille:i386

Conversation

@ccoVeille
Copy link
Copy Markdown
Contributor

@ccoVeille ccoVeille commented Sep 22, 2025

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

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.

This PR applies kubernetes-sigs/yaml#120 to from https://github.com/kubernetes-sigs/yaml to yaml/go-yaml

This bug was identified and fixed by @arthurbdiniz

Fixes #128

@ccoVeille ccoVeille force-pushed the i386 branch 5 times, most recently from 936c4f7 to 9e513c3 Compare September 22, 2025 01:48
@ccoVeille ccoVeille marked this pull request as ready for review September 22, 2025 01:50
Copilot AI review requested due to automatic review settings September 22, 2025 01:50
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes cross-architecture compatibility issues in Go YAML tests by addressing integer type handling for large values that exceed 32-bit integer ranges. The changes ensure tests work correctly on both 32-bit and 64-bit platforms by explicitly using int64 types for large integer constants.

  • Switched test expectations from map[string]any and map[string]int to map[string]int64 for large integer values
  • Enhanced CI/CD pipeline to test across multiple architectures including 32-bit systems
  • Added proper handling for race detection testing based on architecture constraints

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
decode_test.go Updated test expectations to use int64 for large integer constants to prevent overflow on 32-bit systems
.github/workflows/go.yaml Expanded CI matrix to test multiple OS/architecture combinations and handle 32-bit specific constraints

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread decode_test.go Outdated
Comment thread .github/workflows/go.yaml Outdated
Comment thread .github/workflows/go.yaml Outdated
@dims
Copy link
Copy Markdown
Contributor

dims commented Sep 26, 2025

/assign @liggitt

Comment thread decode_test.go Outdated
Comment thread decode_test.go Outdated
Comment thread .github/workflows/go.yaml Fixed
@ingydotnet
Copy link
Copy Markdown
Member

@ccoVeille How are you feeling on this PR?

Comment thread decode_test.go Outdated
@ccoVeille
Copy link
Copy Markdown
Contributor Author

@ccoVeille How are you feeling on this PR?

For me this PR should be merged, code is fine now.

I wish I have a few approvals, but it could be merged as this, I think.

@liggitt
Copy link
Copy Markdown
Contributor

liggitt commented Oct 2, 2025

changes lgtm, I'd suggest squashing commits

Copy link
Copy Markdown
Member

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

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

LGTM

@ingydotnet ingydotnet self-requested a review October 23, 2025 22:04
@ingydotnet
Copy link
Copy Markdown
Member

@ccoVeille the current changes to .github/workflows/go.yaml feel like they don't belong here. Is the branch out of sync?

@ccoVeille
Copy link
Copy Markdown
Contributor Author

@ccoVeille the current changes to .github/workflows/go.yaml feel like they don't belong here. Is the branch out of sync?

Could you please spot a line of the file that seems out of the PR scope ?

The changes I'm introducing are about testing all architectures (os, CPU and 32/64bits) in the unit tests. Something that was missing and caused the issues to be undetected.

So I'm fixing the unit tests. Make sure the issues cannot happen again.

Maybe I introduced a change that shouldn't be there. Please help to spot the issue if there are any

@ingydotnet ingydotnet force-pushed the i386 branch 5 times, most recently from 864d27c to 9a8512b Compare December 21, 2025 16:50
arthurbdiniz and others added 2 commits December 21, 2025 09:19
Add multi-platform CI testing for darwin/amd64, darwin/arm64,
windows/amd64, linux/386, and windows/386 to ensure go-yaml
works correctly across all supported architectures.

Signed-off-by: Arthur Diniz <arthurbdiniz@gmail.com>
Co-authored-by: Jordan Liggitt <liggitt@google.com>
@ingydotnet
Copy link
Copy Markdown
Member

@liggitt @stefanprodan

I got this older PR resolved and working again with the current code. Can you give it a quick review, please?

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread decode_test.go Outdated
Comment thread decode_test.go Outdated
Comment thread decode_test.go
Comment thread decode_test.go Outdated
@ingydotnet
Copy link
Copy Markdown
Member

@ccoVeille you might want to look it over as well.

Copy link
Copy Markdown
Contributor Author

@ccoVeille ccoVeille left a comment

Choose a reason for hiding this comment

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

I'm good with the PR.

Comment thread .github/workflows/go.yaml
@ingydotnet
Copy link
Copy Markdown
Member

I'm good with the PR.

Thanks for checking. Given that I'm going to go ahead and merge it.

@ingydotnet ingydotnet merged commit 25c12a8 into yaml:main Dec 21, 2025
22 checks passed
@ccoVeille ccoVeille deleted the i386 branch December 21, 2025 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tests don't pass of a i386 arch

8 participants