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

Detect file reads that are longer than expected #24708

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

fmeum
Copy link
Collaborator

@fmeum fmeum commented Dec 16, 2024

When Bazel knows the size of a file, it can also detect whether it would go past this size while reading the file. This is virtually free due to using a buffered stream and can catch cases of concurrent modifications or even bugs in Bazel.

Work towards #24694

When Bazel knows the size of a file, it can also detect whether it would go past this size while reading the file. This is virtually free due to using a buffered stream and can catch cases of concurrent modifications or even bugs in Bazel.
@github-actions github-actions bot added the awaiting-review PR is awaiting review from an assigned reviewer label Dec 16, 2024
@fmeum fmeum requested a review from tjgq December 16, 2024 13:05
@@ -844,16 +844,37 @@ public static String readContent(Path inputFile, Charset charset) throws IOExcep
}

/**
* Reads at most {@code limit} bytes from {@code inputFile} and returns it as a byte array.
* Reads at most {@code limit} bytes from {@code inputFile} and returns them as a byte array.
*
* @throws IOException if there was an error.
*/
public static byte[] readContentWithLimit(Path inputFile, int limit) throws IOException {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Within Bazel, this function is now only called by tests. I can get rid of it if that's also the case for Blaze.

Copy link
Member

Choose a reason for hiding this comment

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

It's not used anywhere else internally. I guess we can get rid of it.

@fmeum fmeum requested review from meteorcloudy and removed request for tjgq December 16, 2024 13:06
@@ -844,16 +844,37 @@ public static String readContent(Path inputFile, Charset charset) throws IOExcep
}

/**
* Reads at most {@code limit} bytes from {@code inputFile} and returns it as a byte array.
* Reads at most {@code limit} bytes from {@code inputFile} and returns them as a byte array.
*
* @throws IOException if there was an error.
*/
public static byte[] readContentWithLimit(Path inputFile, int limit) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

It's not used anywhere else internally. I guess we can get rid of it.

@iancha1992 iancha1992 added the team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. label Dec 16, 2024
@meteorcloudy meteorcloudy added team-Core Skyframe, bazel query, BEP, options parsing, bazelrc and removed team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. labels Dec 17, 2024
@meteorcloudy meteorcloudy requested a review from haxorz December 17, 2024 08:49
Copy link
Contributor

@haxorz haxorz left a comment

Choose a reason for hiding this comment

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

Nice!

@@ -917,19 +881,27 @@ private LongReadIOException(Path path, int fileSize) {
* the number of bytes read.
*
* <p>Use this method when you already know the size of the file. The check is intended to catch
* issues where filesystems or external interference results in truncated or concurrently modified
* files.
* issues where filesystems or external interference results in truncated or concurrent
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit [clarity]: Imo something like the following more clearly conveys the intended meaning while keeping your word choice. This is an optional suggestion, so feel free to ignore!

where the filesystem incorrectly returns truncated file contents, or where an external modification has concurrently truncated or appended to the file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that's clearer! Can you make the change during the import?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure

@meteorcloudy fyi since I'm not sure who is going to be mailed the internal CL

Copy link
Member

Choose a reason for hiding this comment

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

gTech will do the import, but I can suggest the edition, np!

Copy link
Member

Choose a reason for hiding this comment

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

Or I can just edit this PR, done ;)

@fmeum
Copy link
Collaborator Author

fmeum commented Dec 17, 2024

@bazel-io fork 8.0.1

@meteorcloudy meteorcloudy added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-review PR is awaiting review from an assigned reviewer labels Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally team-Core Skyframe, bazel query, BEP, options parsing, bazelrc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants