-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Fix CSV render error #17406
Fix CSV render error #17406
Conversation
Shall we add a unit test for this in gitdiff/csv_test.go? Easy to generate more than 2048 chars of a CSV with https://www.convertcsv.com/generate-test-data.htm Or maybe even more than 1e4 bytes to make sure nothing gets closed/lost? |
modules/csv/csv.go
Outdated
var buf = make([]byte, 1e4) | ||
n, err := rd.Read(buf) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you trying to fill that buffer if you at all can? There's no guarantee even if the size is 16Mb that the buffer will contain more than one byte. You need to use ReadAtLeast
or ReadFull
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add this in a follow up PR because that needs to be fixed in more places like LFS pointer detection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2nd
Please send backport to v1.15 |
closed go-gitea#17378 Both errors from go-gitea#17378 were caused by go-gitea#15175. Problem 1 (error with added file): `ToUTF8WithFallbackReader` creates a `MultiReader` from a `byte[2048]` and the remaining reader. `CreateReaderAndGuessDelimiter` tries to read 10000 bytes from this reader but only gets 2048 because that's the first reader in the `MultiReader`. Then the `if size < 1e4` thinks the input is at EOF and just returns that. Problem 2 (error with changed file): The blob reader gets defer closed. That was fine because the old version reads the whole file into memory. Now with the streaming version the close needs to defer after the method.
I still think |
Backport #17406. Closes #17378 Both errors from #17378 were caused by #15175. Problem 1 (error with added file): `ToUTF8WithFallbackReader` creates a `MultiReader` from a `byte[2048]` and the remaining reader. `CreateReaderAndGuessDelimiter` tries to read 10000 bytes from this reader but only gets 2048 because that's the first reader in the `MultiReader`. Then the `if size < 1e4` thinks the input is at EOF and just returns that. Problem 2 (error with changed file): The blob reader gets defer closed. That was fine because the old version reads the whole file into memory. Now with the streaming version the close needs to defer after the method. Co-authored-by: zeripath <[email protected]>
Unforunately go-gitea#17435 is a somewhat critical bug and therefore we should really release 1.15.6 as soon as possible. ## [1.15.6](https://github.com/go-gitea/gitea/releases/tag/v1.15.6) - 2021-10-27 * BUGFIXES * Prevent panic in serv.go with Deploy Keys (go-gitea#17434) (go-gitea#17435) * Fix CSV render error (go-gitea#17406) (go-gitea#17431) * Read expected buffer size (go-gitea#17409) (go-gitea#17430) Signed-off-by: Andrew Thornton <[email protected]>
* Changelog 1.15.6 Unforunately #17435 is a somewhat critical bug and therefore we should really release 1.15.6 as soon as possible. ## [1.15.6](https://github.com/go-gitea/gitea/releases/tag/v1.15.6) - 2021-10-27 * BUGFIXES * Prevent panic in serv.go with Deploy Keys (#17434) (#17435) * Fix CSV render error (#17406) (#17431) * Read expected buffer size (#17409) (#17430) Signed-off-by: Andrew Thornton <[email protected]> * Add 17456 and its backport Signed-off-by: Andrew Thornton <[email protected]> * Add 17464 Signed-off-by: Andrew Thornton <[email protected]> * Add final pr * Update date Co-authored-by: wxiaoguang <[email protected]>
Frontport go-gitea#17457 ## [1.15.6](https://github.com/go-gitea/gitea/releases/tag/v1.15.6) - 2021-10-28 * BUGFIXES * Prevent panic in serv.go with Deploy Keys (go-gitea#17434) (go-gitea#17435) * Fix CSV render error (go-gitea#17406) (go-gitea#17431) * Read expected buffer size (go-gitea#17409) (go-gitea#17430) * Ensure that restricted users can access repos for which they are members (go-gitea#17460) (go-gitea#17464) * Make commit-statuses popup show correctly (go-gitea#17447) (go-gitea#17466) * TESTING * Add integration tests for private.NoServCommand and private.ServCommand (go-gitea#17456) (go-gitea#17463)
Frontport #17457 ## [1.15.6](https://github.com/go-gitea/gitea/releases/tag/v1.15.6) - 2021-10-28 * BUGFIXES * Prevent panic in serv.go with Deploy Keys (#17434) (#17435) * Fix CSV render error (#17406) (#17431) * Read expected buffer size (#17409) (#17430) * Ensure that restricted users can access repos for which they are members (#17460) (#17464) * Make commit-statuses popup show correctly (#17447) (#17466) * TESTING * Add integration tests for private.NoServCommand and private.ServCommand (#17456) (#17463)
closed go-gitea#17378 Both errors from go-gitea#17378 were caused by go-gitea#15175. Problem 1 (error with added file): `ToUTF8WithFallbackReader` creates a `MultiReader` from a `byte[2048]` and the remaining reader. `CreateReaderAndGuessDelimiter` tries to read 10000 bytes from this reader but only gets 2048 because that's the first reader in the `MultiReader`. Then the `if size < 1e4` thinks the input is at EOF and just returns that. Problem 2 (error with changed file): The blob reader gets defer closed. That was fine because the old version reads the whole file into memory. Now with the streaming version the close needs to defer after the method.
Frontport go-gitea#17457 ## [1.15.6](https://github.com/go-gitea/gitea/releases/tag/v1.15.6) - 2021-10-28 * BUGFIXES * Prevent panic in serv.go with Deploy Keys (go-gitea#17434) (go-gitea#17435) * Fix CSV render error (go-gitea#17406) (go-gitea#17431) * Read expected buffer size (go-gitea#17409) (go-gitea#17430) * Ensure that restricted users can access repos for which they are members (go-gitea#17460) (go-gitea#17464) * Make commit-statuses popup show correctly (go-gitea#17447) (go-gitea#17466) * TESTING * Add integration tests for private.NoServCommand and private.ServCommand (go-gitea#17456) (go-gitea#17463)
closed #17378
Both errors from #17378 were caused by #15175.
Problem 1 (error with added file):
ToUTF8WithFallbackReader
creates aMultiReader
from abyte[2048]
and the remaining reader.CreateReaderAndGuessDelimiter
tries to read 10000 bytes from this reader but only gets 2048 because that's the first reader in theMultiReader
. Then theif size < 1e4
thinks the input is at EOF and just returns that.Problem 2 (error with changed file):
The blob reader gets defer closed. That was fine because the old version reads the whole file into memory. Now with the streaming version the close needs to defer after the method.