Tests fail on s390x and go >= 1.13

Bug #1883770 reported by Andreas Hasenack
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Go
Fix Released
Unknown
golang-1.13 (Ubuntu)
New
Undecided
Unassigned
golang-1.14 (Ubuntu)
New
Undecided
Unassigned
golang-yaml.v2 (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

```
FAIL: decode_test.go:775: S.TestDecoderSingleDocument
...
test 60: "a: 1"
test 61: "a: 1.0"
decode_test.go:790:
    c.Assert(value.Elem().Interface(), DeepEquals, item.value)
... obtained *struct { A int } = &struct { A int }{A:0}
... expected *struct { A int } = &struct { A int }{A:1}
...
FAIL: decode_test.go:750: S.TestUnmarshal
...
test 60: "a: 1"
test 61: "a: 1.0"
decode_test.go:759:
    c.Assert(value.Elem().Interface(), DeepEquals, item.value, Commentf("error: %v", err))
... obtained *struct { A int } = &struct { A int }{A:0}
... expected *struct { A int } = &struct { A int }{A:1}
... error: yaml: unmarshal errors:
  line 1: cannot unmarshal !!float `1.0` into int

OOPS: 30 passed, 2 FAILED
--- FAIL: Test (7.21s)
=== RUN ExampleUnmarshal_embedded
--- PASS: ExampleUnmarshal_embedded (0.00s)
FAIL
exit status 1
FAIL gopkg.in/yaml.v2 7.274s
```

Further experimentation with older releases of ubuntu, but only installing golang-go from ubuntu, and using golang-yaml.v2's upstream git repo for the test with "go test -v", showed that the tests:
- PASS: go 1.10~4ubuntu1, 1.12~1ubuntu1
- FAIL: go 1.13~1ubuntu2, 1.14~1

Revision history for this message
Andreas Hasenack (ahasenack) wrote :
Revision history for this message
Andreas Hasenack (ahasenack) wrote :

The example code from the upstream readme file fails on s390x (but works on amd64) if I change it to use a float:

package main

import (
        "fmt"
        "log"

        "gopkg.in/yaml.v2"
)

var data = `
a: Easy!
b:
  c: 1.0
  d: [3, 4]
`

// Note: struct fields must be public in order for unmarshal to
// correctly populate the data.
type T struct {
        A string
        B struct {
                RenamedC int `yaml:"c"`
                D []int `yaml:",flow"`
        }
}

func main() {
        t := T{}

        err := yaml.Unmarshal([]byte(data), &t)
        if err != nil {
                log.Fatalf("error: %v", err)
        }
        fmt.Printf("--- t:\n%v\n\n", t)

        d, err := yaml.Marshal(&t)
        if err != nil {
                log.Fatalf("error: %v", err)
        }
        fmt.Printf("--- t dump:\n%s\n\n", string(d))

        m := make(map[interface{}]interface{})

        err = yaml.Unmarshal([]byte(data), &m)
        if err != nil {
                log.Fatalf("error: %v", err)
        }
        fmt.Printf("--- m:\n%v\n\n", m)

        d, err = yaml.Marshal(&m)
        if err != nil {
                log.Fatalf("error: %v", err)
        }
        fmt.Printf("--- m dump:\n%s\n\n", string(d))
}

Revision history for this message
Andreas Hasenack (ahasenack) wrote :

Sorry, forgot the output:
On s390x:
390x:~$ go build example.go
ubuntu@s390x:~$ ./example
2020/06/16 19:02:53 error: yaml: unmarshal errors:
  line 4: cannot unmarshal !!float `1.0` into int

On amd64:
andreas@nsnx:~$ go build example.go
andreas@nsnx:~$ ./example
--- t:
{Easy! {1 [3 4]}}

--- t dump:
a: Easy!
b:
  c: 1
  d: [3, 4]

--- m:
map[a:Easy! b:map[c:1 d:[3 4]]]

--- m dump:
a: Easy!
b:
  c: 1
  d:
  - 3
  - 4

Revision history for this message
Andreas Hasenack (ahasenack) wrote :

This crazy patch makes the test pass on s390x in groovy:
--- a/decode.go
+++ b/decode.go
@@ -500,7 +500,8 @@
     return true
    }
   case float64:
- if resolved <= math.MaxInt64 && !out.OverflowInt(int64(resolved)) {
+ is_overflow := out.OverflowInt(int64(resolved))
+ if resolved <= math.MaxInt64 && !is_overflow {
     out.SetInt(int64(resolved))
     return true
    }

Revision history for this message
Andreas Hasenack (ahasenack) wrote :

I filed an issue with golang upstream at https://github.com/golang/go/issues/39651

Revision history for this message
Andreas Hasenack (ahasenack) wrote :

Marking the yaml.v2 task as incomplete pending confirmation it's a bug in golang.

Changed in golang-yaml.v2 (Ubuntu):
status: New → Incomplete
Revision history for this message
Andreas Hasenack (ahasenack) wrote :

Upstream has an MP: https://go-review.googlesource.com/c/go/+/238628/

Marking the yaml.v2 task as invalid here.

Changed in golang-yaml.v2 (Ubuntu):
status: Incomplete → Invalid
Changed in golang:
status: Unknown → New
Revision history for this message
Andreas Hasenack (ahasenack) wrote :
Changed in golang:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.