Skip to content

strconv: ParseFloat panics on very long, valid inputs #2642

@remyoudompheng

Description

@remyoudompheng
What steps will reproduce the problem?
1. Compile and run the following code:

package main

import (
    "fmt"
    "strconv"
)

func main() {
  var longnumber [4096]byte
  for i := range longnumber {
     longnumber[i] = '2'
  }
  longnumber[1] = '.'
  x, er := strconv.ParseFloat(string(longnumber[:]), 64)
  fmt.Println(x, er)
}

What is the expected output?

2.2222222222222222 <nil>

What do you see instead?

panic: runtime error: index out of range

goroutine 1 [running]:
strconv.(*decimal).set(0xf8400210d4, 0xf840024000, 0x1000, 0x0, 0xf840021100, ...)
    /opt/remy/go/src/pkg/strconv/atof.go:91 +0x315
----- stack segment boundary -----
strconv.atof64(0xf840024000, 0xf800001000, 0xf840021488, 0x0, 0x0, ...)
    /opt/remy/go/src/pkg/strconv/atof.go:383 +0xe0
strconv.ParseFloat(0xf840024000, 0x1000, 0xf800000040, 0x1000, 0x0, ...)
    /opt/remy/go/src/pkg/strconv/atof.go:432 +0x8d
main.main()
    /tmp/truc.go:14 +0xb9
----- stack segment boundary -----


Which compiler are you using (5g, 6g, 8g, gccgo)?

6g

Which operating system are you using?

linux

Which revision are you using?  (hg identify)

c956aa39a269+ (tip)

Please provide any additional information below.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions