Fix integer overflow for scene size on 32bit systems (#994)

* Fix integer overflow for scene size on 32bit systems
* Cast to double in sqlite to prevent potential overflow
* Add migration to reset scene sizes and scan logic to repopulate if empty
This commit is contained in:
InfiniteTF
2020-12-22 00:29:53 +01:00
committed by GitHub
parent e883e5fe27
commit e84c92355e
9 changed files with 19 additions and 15 deletions

View File

@@ -246,8 +246,8 @@ func (qb *ImageQueryBuilder) Count() (int, error) {
return runCountQuery(buildCountQuery("SELECT images.id FROM images"), nil)
}
func (qb *ImageQueryBuilder) Size() (uint64, error) {
return runSumQuery("SELECT SUM(size) as sum FROM images", nil)
func (qb *ImageQueryBuilder) Size() (float64, error) {
return runSumQuery("SELECT SUM(cast(size as double)) as sum FROM images", nil)
}
func (qb *ImageQueryBuilder) CountByStudioID(studioID int) (int, error) {

View File

@@ -254,8 +254,8 @@ func (qb *SceneQueryBuilder) Count() (int, error) {
return runCountQuery(buildCountQuery("SELECT scenes.id FROM scenes"), nil)
}
func (qb *SceneQueryBuilder) Size() (uint64, error) {
return runSumQuery("SELECT SUM(size) as sum FROM scenes", nil)
func (qb *SceneQueryBuilder) Size() (float64, error) {
return runSumQuery("SELECT SUM(cast(size as double)) as sum FROM scenes", nil)
}
func (qb *SceneQueryBuilder) CountByStudioID(studioID int) (int, error) {

View File

@@ -332,16 +332,16 @@ func runCountQuery(query string, args []interface{}) (int, error) {
return result.Int, nil
}
func runSumQuery(query string, args []interface{}) (uint64, error) {
func runSumQuery(query string, args []interface{}) (float64, error) {
// Perform query and fetch result
result := struct {
Uint uint64 `db:"sum"`
Float64 float64 `db:"sum"`
}{0}
if err := database.DB.Get(&result, query, args...); err != nil && err != sql.ErrNoRows {
return 0, err
}
return result.Uint, nil
return result.Float64, nil
}
func executeFindQuery(tableName string, body string, args []interface{}, sortAndPagination string, whereClauses []string, havingClauses []string) ([]int, int) {