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

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

Merged
merged 5 commits into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions graphql/schema/types/stats.graphql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
type StatsResultType {
scene_count: Int!
scenes_size: Int!
scenes_size: Float!
image_count: Int!
images_size: Int!
images_size: Float!
gallery_count: Int!
performer_count: Int!
studio_count: Int!
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ func (r *queryResolver) Stats(ctx context.Context) (*models.StatsResultType, err
tagsCount, _ := tagsQB.Count()
return &models.StatsResultType{
SceneCount: scenesCount,
ScenesSize: int(scenesSize),
ScenesSize: scenesSize,
ImageCount: imageCount,
ImagesSize: int(imageSize),
ImagesSize: imageSize,
GalleryCount: galleryCount,
PerformerCount: performersCount,
StudioCount: studiosCount,
Expand Down
2 changes: 1 addition & 1 deletion pkg/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

var DB *sqlx.DB
var dbPath string
var appSchemaVersion uint = 16
var appSchemaVersion uint = 17
var databaseSchemaVersion uint

const sqlite3Driver = "sqlite3ex"
Expand Down
1 change: 1 addition & 0 deletions pkg/database/migrations/17_reset_scene_size.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `scenes` SET `size` = NULL;
6 changes: 3 additions & 3 deletions pkg/manager/task_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func (t *ScanTask) scanScene() *models.Scene {
// if the mod time of the file is different than that of the associated
// scene, then recalculate the checksum and regenerate the thumbnail
modified := t.isFileModified(fileModTime, scene.FileModTime)
if modified {
if modified || !scene.Size.Valid {
scene, err = t.rescanScene(scene, fileModTime)
if err != nil {
logger.Error(err.Error())
Expand Down Expand Up @@ -534,7 +534,7 @@ func (t *ScanTask) scanScene() *models.Scene {
Height: sql.NullInt64{Int64: int64(videoFile.Height), Valid: true},
Framerate: sql.NullFloat64{Float64: videoFile.FrameRate, Valid: true},
Bitrate: sql.NullInt64{Int64: videoFile.Bitrate, Valid: true},
Size: sql.NullString{String: strconv.Itoa(int(videoFile.Size)), Valid: true},
Size: sql.NullString{String: strconv.FormatInt(videoFile.Size, 10), Valid: true},
FileModTime: models.NullSQLiteTimestamp{
Timestamp: fileModTime,
Valid: true,
Expand Down Expand Up @@ -610,7 +610,7 @@ func (t *ScanTask) rescanScene(scene *models.Scene, fileModTime time.Time) (*mod
Height: &sql.NullInt64{Int64: int64(videoFile.Height), Valid: true},
Framerate: &sql.NullFloat64{Float64: videoFile.FrameRate, Valid: true},
Bitrate: &sql.NullInt64{Int64: videoFile.Bitrate, Valid: true},
Size: &sql.NullString{String: strconv.Itoa(int(videoFile.Size)), Valid: true},
Size: &sql.NullString{String: strconv.FormatInt(videoFile.Size, 10), Valid: true},
FileModTime: &models.NullSQLiteTimestamp{
Timestamp: fileModTime,
Valid: true,
Expand Down
4 changes: 2 additions & 2 deletions pkg/models/querybuilder_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/models/querybuilder_scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/models/querybuilder_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions ui/v2.5/src/components/Changelog/versions/v050.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#### 💥 **Note: After upgrading, all scene file sizes will be 0B until a new [scan](/settings?tab=tasks) is run.

### ✨ New Features
* Add organized flag for scenes, galleries and images.
* Allow configuration of visible navbar items.
Expand All @@ -13,4 +15,5 @@
* Support configurable number of threads for scanning and generation.

### 🐛 Bug fixes
* Corrected file sizes on 32bit platforms
* Fixed login redirect to remember the current page.