From 2683a944fb1b42033e31fc167e71a7b57834b368 Mon Sep 17 00:00:00 2001 From: Anton Medvedev Date: Wed, 6 Sep 2023 09:31:11 +0200 Subject: [PATCH] Add check for int64->int conversion --- parser/parser.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/parser/parser.go b/parser/parser.go index b7a8752d5..d4a870f71 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -2,6 +2,7 @@ package parser import ( "fmt" + "math" "strconv" "strings" @@ -310,6 +311,10 @@ func (p *parser) parseSecondary() Node { if err != nil { p.error("invalid hex literal: %v", err) } + if number > math.MaxInt { + p.error("integer literal is too large") + return nil + } node := &IntegerNode{Value: int(number)} node.SetLocation(token.Location) return node @@ -326,6 +331,10 @@ func (p *parser) parseSecondary() Node { if err != nil { p.error("invalid integer literal: %v", err) } + if number > math.MaxInt { + p.error("integer literal is too large") + return nil + } node := &IntegerNode{Value: int(number)} node.SetLocation(token.Location) return node