Skip to content

Inconsistent strconv.Atoi behavior for 32bit release, lead to error or data corruption. #20161

@wxiaoguang

Description

@wxiaoguang
Contributor

strconv.Atoi has different behavior:

$ GOARCH=386 go run test-int.go
2147483647 (0x80bee40,0x8c8e000)

$ GOARCH=amd64 go run test-int.go
4294967295 (0x0,0x0)

$ cat test-int.go
package main

import "strconv"

func main() {
	println(strconv.Atoi("4294967295"))
}

For example, in XORM:

image

A user has reported that Gitea 1.17 failed with error:

...
2022/06/28 11:47:32 routers/common/db.go:34:InitDBEngine() [I] Backing off for 3 seconds
2022/06/28 11:47:35 routers/common/db.go:27:InitDBEngine() [I] ORM engine initialization attempt #9/10...
2022/06/28 11:47:35 routers/common/db.go:33:InitDBEngine() [E] ORM engine initialization attempt #9/10 failed. Error: sync database struct error: strconv.Atoi: parsing "4294967295": value out of range
2022/06/28 11:47:35 routers/common/db.go:34:InitDBEngine() [I] Backing off for 3 seconds
2022/06/28 11:47:38 routers/common/db.go:27:InitDBEngine() [I] ORM engine initialization attempt #10/10...
2022/06/28 11:47:38 routers/init.go:68:mustInitCtx() [F] code.gitea.io/gitea/routers/common.InitDBEngine(ctx) failed: sync database struct error: strconv.Atoi: parsing "4294967295": value out of range

Activity

added
issue/criticalThis issue should be fixed ASAP. If it is a PR, the PR should be merged ASAP
on Jun 28, 2022
aha-tech

aha-tech commented on Jul 10, 2022

@aha-tech

I'm having the same issue using gitea-1.17-linux-arm-6 on a Raspberry Pi 4 Model B (32-bit ARMv7)

nesc1

nesc1 commented on Jul 12, 2022

@nesc1

Also here same problem when executing:

2022/07/12 13:09:39 models/db/engine.go:126:SyncAllTables() [I] [SQL] SELECT `COLUMN_NAME`, `IS_NULLABLE`, `COLUMN_DEFAULT`, `COLUMN_TYPE`, `COLUMN_KEY`, `EXTRA`, `COLUMN_COMMENT`, `CHARACTER_MAXIMUM_LENGTH`, (INSTR(VERSION(), 'maria') > 0 && (SUBSTRING_INDEX(VERSION(), '.', 1) > 10 || (SUBSTRING_INDEX(VERSION(), '.', 1) = 10 && (SUBSTRING_INDEX(SUBSTRING(VERSION(), 4), '.', 1) > 2 || (SUBSTRING_INDEX(SUBSTRING(VERSION(), 4), '.', 1) = 2 && SUBSTRING_INDEX(SUBSTRING(VERSION(), 6), '-', 1) >= 7))))) AS NEEDS_QUOTE FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ? ORDER BY `COLUMNS`.ORDINAL_POSITION ASC [gitea pull_auto_merge] - 2.49032ms
2022/07/12 13:09:39 routers/common/db.go:33:InitDBEngine() [E] ORM engine initialization attempt #6/10 failed. Error: sync database struct error: strconv.Atoi: parsing "4294967295": value out of range
2022/07/12 13:09:39 routers/common/db.go:34:InitDBEngine() [I] Backing off for 3 seconds

it seems that CHARACTER_MAXIMUM_LENGTH with value 4294967295 creates the problem...

Now server is unusable because I can not return to previous version because I did not backup the database....

zeripath

zeripath commented on Jul 12, 2022

@zeripath
Contributor
func Atoi(s string) (int, error) {

on 32bit systems int is most likely to be int32 rather than int64.

The problem is that xorm *schemas.Column uses signed int for column length and should either: a) use int64 or b) uint or even uint64 - however this is a breaking change in xorm.

zeripath

zeripath commented on Jul 12, 2022

@zeripath
Contributor
added this to the 1.17.0 milestone on Jul 14, 2022
wxiaoguang

wxiaoguang commented on Jul 15, 2022

@wxiaoguang
Author
wxiaoguang

wxiaoguang commented on Jul 15, 2022

@wxiaoguang
ContributorAuthor

If you have met this bug, please download latest from https://dl.gitea.io/gitea/

locked and limited conversation to collaborators on May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue/criticalThis issue should be fixed ASAP. If it is a PR, the PR should be merged ASAPtype/bug

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Participants

      @zeripath@wxiaoguang@nesc1@6543@aha-tech

      Issue actions

        Inconsistent `strconv.Atoi` behavior for 32bit release, lead to error or data corruption. · Issue #20161 · go-gitea/gitea