Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integer overflow on ARMv6 (32-bit) #51

Open
climech opened this issue Jun 12, 2021 · 1 comment
Open

Integer overflow on ARMv6 (32-bit) #51

climech opened this issue Jun 12, 2021 · 1 comment
Assignees

Comments

@climech
Copy link

climech commented Jun 12, 2021

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
@silverspace
Copy link

Is this being worked on? I also encountered this issue, which is caused by query_result.go calling redis.Int(v, nil) instead of redis.Int64(v, nil).

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

No branches or pull requests

3 participants