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

sd creates corrupt files ("failed to write whole buffer") #38

Closed
sharkdp opened this issue Jun 16, 2019 · 4 comments
Closed

sd creates corrupt files ("failed to write whole buffer") #38

sharkdp opened this issue Jun 16, 2019 · 4 comments

Comments

@sharkdp
Copy link

sharkdp commented Jun 16, 2019

If the replacement string has a different length than the search pattern, sd either fails with an error "failed to write whole buffer" (when the replacement string is longer) or even leaves behind corrupt files (when the replacement string is shorter).

How to reproduce:

echo "foo" > dummy

▶ sd "foo" "fo" dummy

▶ hexdump -C dummy
00000000  66 6f 0a 00                                       |fo..|
00000004

Notice the additional zero byte (00) at then end.

@sharkdp
Copy link
Author

sharkdp commented Jun 16, 2019

I just now saw that this has already been reported in #37. However, the effect on Linux seems to be a bit different.

@ghost
Copy link

ghost commented Jun 16, 2019

Same problems on FreeBSD.

@chmln chmln closed this as completed in ab457f7 Jun 16, 2019
@chmln
Copy link
Owner

chmln commented Jun 16, 2019

Thanks a lot for reporting this and your correct analysis @sharkdp. The error was caused by an improper size pre-allocated for the file-backed memory map.

I've just released v0.6.1 addressing this issue.

@sharkdp
Copy link
Author

sharkdp commented Jun 16, 2019

Thank you very much for the quick bugfix!

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

No branches or pull requests

2 participants