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

operator/pkg/util: Curious about Adding a Data Limit Check in ioCopyN? #5668

Open
mohamedawnallah opened this issue Oct 11, 2024 · 3 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature.

Comments

@mohamedawnallah
Copy link
Contributor

Description

Currently, the ioCopyN function does not enforce a limit on the amount of data it processes from the tar.Reader. This can lead to potential Denial of Service (DoS) vulnerabilities through decompression bombs, where maliciously crafted tar files could cause excessive resource consumption.

// ioCopyN fix Potential DoS vulnerability via decompression bomb.
func ioCopyN(outFile *os.File, tr *tar.Reader) error {
for {
if _, err := io.CopyN(outFile, tr, 1024); err != nil {
if errors.Is(err, io.EOF) {
break
}
return err
}
}
return nil
}

Proposed Changes

Implement a data limit check in the ioCopyN function to prevent excessive data processing. This can be achieved by adding the following code to track the total number of bytes written and enforce a maximum size limit:

totalWritten += n
if totalWritten > maxSize {
    return fmt.Errorf("data limit exceeded: total written %d bytes, maximum allowed %d bytes", totalWritten, maxSize)
}

What do you think ? 🤔

@mohamedawnallah mohamedawnallah added the kind/feature Categorizes issue or PR as related to a new feature. label Oct 11, 2024
@prakrit55
Copy link

hey @mohamedawnallah, if its open I would like to fix it

@mohamedawnallah
Copy link
Contributor Author

Hey @prakrit55, I've submitted an improvement suggestion that hasn't been confirmed yet. Could @XiShanYongYe-Chang and @zhzhuang-zju also review it?

@zhzhuang-zju
Copy link
Contributor

@mohamedawnallah thanks for raising this issue. I have two questions regarding this:

  • Is this a known issue? Is it a widely accepted practice to add a data limit check?
  • What should the maxSize be set to?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature.
Projects
Status: No status
Development

No branches or pull requests

3 participants