Skip to content

Division by zero in formatFileRow() causes gdu to hang #358

@xroberx

Description

@xroberx

Description:

gdu hangs when entering a directory in which all the files have a size of 0

Steps to reproduce the behavior:

  1. mkdir /tmp/gdu_test
  2. touch /tmp/gdu_test/empty_file.txt
  3. gdu /tmp/gdu_test

The bug is in the following code from tui/format.go:

case ui.ShowApparentSize: 
	part = int(float64(item.GetSize()) / float64(maxSize) * 100.0)   
default:   
	part = int(float64(item.GetUsage()) / float64(maxUsage) * 100.0)  

When all the items in the target directory have a size of 0, then maxSize/maxUsage = 0. Also, item.GetSize() and item.GetUsage() are equal to 0. This results in a 0/0 division, which equals NaN. Then, the casting to int results in the following number: -9223372036854775808.

If at least one file in the target directory has a size > 0, then the bug is not triggered. This is because maxSize/maxUsage are > 0, which avoids dividing by 0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions