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

files.PutFile: panic when file with zero size #93

Closed
wuxu92 opened this issue Dec 11, 2023 · 0 comments · Fixed by #94
Closed

files.PutFile: panic when file with zero size #93

wuxu92 opened this issue Dec 11, 2023 · 0 comments · Fixed by #94

Comments

@wuxu92
Copy link
Contributor

wuxu92 commented Dec 11, 2023

fileInfo.Size() can be 0 so Line 25 will cause 0/0 which is

The result of a floating-point or complex division by zero is not specified beyond the IEEE-754 standard; whether a run-time panic occurs is implementation-specific.
Ref: https://go.dev/ref/spec#Floating_point_operators

The division did not cause panic but the value of chucks is Inf but panic with "makechan: size out of range" in line 35.

fileSize := fileInfo.Size()
chunkSize := 4 * 1024 * 1024 // 4MB
if chunkSize > int(fileSize) {
chunkSize = int(fileSize)
}
chunks := int(math.Ceil(float64(fileSize) / float64(chunkSize*1.0)))
workerCount := parallelism
if workerCount > chunks {
workerCount = chunks
}
var waitGroup sync.WaitGroup
waitGroup.Add(workerCount)
jobs := make(chan int, workerCount)

Related Issue: hashicorp/terraform-provider-azurerm#24171

tombuildsstuff added a commit that referenced this issue Dec 12, 2023
Duplicate of #94 but for `2023-11-03` rather than `2020-08-04`
tombuildsstuff added a commit that referenced this issue Dec 12, 2023
…oads

`2023-11-03/file/files`: fixing #93 for this API version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant