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

2.0 hotfix: Resolve intermittent crash due to zero-byte reads in log reading #1501

Merged
merged 4 commits into from
May 24, 2024

Conversation

Abingcbc
Copy link
Collaborator

问题

超时导致force read后,如果下一次读取是以\n开头的,那么这个\n应该被忽略掉。
但是当只读取了一个\n时,这个回退操作会导致读取的长度nbytes变为0,触发内存越界。

@@ -2087,7 +2090,7 @@ LogFileReader::RemoveLastIncompleteLog(char* buffer, int32_t size, int32_t& roll
*/
StringView LogFileReader::GetLastLine(StringView buffer, size_t end) {
if (end == 0) {
return buffer;
return StringView(buffer.data(), 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

外层函数要处理吗?boost遇到size=0是什么行为?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

补了一个单测,boost的结果是一个空字符串。GetLastLine的返回结果只会用到开始的位置,只要是以buffer.data()开头的,应该没有问题。

@henryzhx8 henryzhx8 added this to the v2.0 milestone May 23, 2024
@henryzhx8 henryzhx8 added the bug Something isn't working label May 23, 2024
@yyuuttaaoo yyuuttaaoo changed the title hotfix: zero nbytes when read log 2.0 hotfix: Resolve intermittent crash due to zero-byte reads in log reading May 23, 2024
@yyuuttaaoo yyuuttaaoo merged commit 664096c into alibaba:2.0 May 24, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants