Skip to content

fix: sys.read: never read files that contain a null byte #837

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

Merged
merged 2 commits into from
Sep 3, 2024

Conversation

g-linville
Copy link
Member

@@ -489,6 +489,12 @@ func SysRead(_ context.Context, _ []string, input string, _ chan<- string) (stri
if len(data) == 0 {
return fmt.Sprintf("The file %s has no contents", params.Filename), nil
}

// Assume the file is not text if it contains a null byte
if bytes.Contains(data, []byte{0}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: bytes.IndexByte is probably slightly more performant.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

Signed-off-by: Grant Linville <[email protected]>
@g-linville g-linville merged commit eaaf0cd into gptscript-ai:main Sep 3, 2024
10 checks passed
@g-linville g-linville deleted the sys-read-null branch September 3, 2024 16:28
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.

3 participants