Skip to content

Integer overflow on ARMv6 (32-bit) #51

Open
@climech

Description

@climech

I noticed redisgraph-go deserializes integers into int instead of int64. Depending on the system, int may be either 64 or 32 bits long. This can cause overflows for larger values, e.g. Unix timestamps beyond Y2038.

Tested on Raspberry Pi Zero W (ARMv6):

package main

import (
	"fmt"
	"log"

	"github.com/gomodule/redigo/redis"
	rg "github.com/redislabs/redisgraph-go"
)

func main() {
	conn, _ := redis.Dial("tcp", "192.168.1.100:6379")
	defer conn.Close()

	graph := rg.GraphNew("test", conn)
	graph.Delete()

	var t int64 = 2147483648
	q1 := fmt.Sprintf(`CREATE (:Person{name: 'John', time_created: %d})`, t)

	if _, err := graph.Query(q1); err != nil {
		log.Fatal(err)
	}

	q2 := `MATCH (p:Person) RETURN p.time_created`

	result, err := graph.Query(q2)
	if err != nil {
		log.Fatal(err)
	}

	result.PrettyPrint()
}

Expected output:

+----------------+
| p.time_created |
+----------------+
|     2147483648 |
+----------------+

Actual output:

+----------------+
| p.time_created |
+----------------+
|              0 |
+----------------+

Calling reflect.TypeOf on the record value returns int.

Note that the node had to be added using a string query, since the other method doesn't accept int64 properties, e.g.:

john := rg.Node{
	Label: "Person",
	Properties: map[string]interface{}{
		"name":         "John",
		"time_created": time.Now().Unix(),
	},
}

graph.AddNode(&john)
graph.Commit()

causes a panic:

panic: Unrecognized type to convert to string

goroutine 1 [running]:
github.com/redislabs/redisgraph-go.ToString(0x60b4a0, 0xc0000b24a0, 0xc000107b40, 0x2)
	/home/tomek/.local/go/pkg/mod/github.com/redislabs/[email protected]+incompatible/utils.go:40 +0x317
github.com/redislabs/redisgraph-go.Node.Encode(0x0, 0x64bfa4, 0x6, 0xc0000b24d0, 0xa, 0xc00009aae0, 0xc0000fe000, 0x10, 0x203000)
	/home/tomek/.local/go/pkg/mod/github.com/redislabs/[email protected]+incompatible/node.go:70 +0x23d
github.com/redislabs/redisgraph-go.(*Graph).Commit(0xc0000fe000, 0xc00009aab0, 0xc0000b24d0, 0xa)
	/home/tomek/.local/go/pkg/mod/github.com/redislabs/[email protected]+incompatible/graph.go:91 +0x19e
main.main()
	/tmp/rgtest/main.go:30 +0x5a5
exit status 2

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions