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

acc: Avoid reading and applying replacements on large files; validate utf8 #2244

Merged
merged 1 commit into from
Jan 28, 2025

Conversation

denik
Copy link
Contributor

@denik denik commented Jan 27, 2025

Changes

  • Do not start replacement / comparison if file is too large or not valid utf-8.
  • This helps to prevent replacements if there is accidentally a large binary (e.g. terraform).

Tests

Found this problem when working on #2242 -- the tests tried to applied replacements on terraform binary and crashed. With this change, an error is reported instead.

… utf-8

This helps to prevent replacements if there is accidentally a large binary (e.g. terraform).
@@ -44,6 +45,7 @@ const (
EntryPointScript = "script"
CleanupScript = "script.cleanup"
PrepareScript = "script.prepare"
MaxFileSize = 100_000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason for 100kb limit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seemed like a reasonable limit on output file. It's conservative - we unlikely to hit it. For context, largest output.txt we have today is acceptance/help/output.txt - 12KB.

info, err := os.Stat(path)
if err != nil {
if !errors.Is(err, os.ErrNotExist) {
t.Errorf("%s: %s", path, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the benefit of using t.Errorf instead of returning the error from tryReading and logging it when the tryReading is called?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general the test helpers should not return errors but raise them directly on t object. This makes the usage less noisy w.r.t all the error checking.

In this particular case I'm using t.Error rather than t.Fatal because I want to see all the status/comparisons on all files.

@denik denik added this pull request to the merge queue Jan 28, 2025
Merged via the queue into main with commit 11436fa Jan 28, 2025
9 checks passed
@denik denik deleted the denik/acc-large-files branch January 28, 2025 10:29
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 this pull request may close these issues.

2 participants