Skip to content

[CSV-158] Fix EOL checking for read array in ExtendedBufferedReader#5

Merged
garydgregory merged 2 commits into
apache:masterfrom
mirasrael:trunk
Jul 7, 2021
Merged

[CSV-158] Fix EOL checking for read array in ExtendedBufferedReader#5
garydgregory merged 2 commits into
apache:masterfrom
mirasrael:trunk

Conversation

@mirasrael

Copy link
Copy Markdown
Contributor

Characters in buffer before offset are unspecified

@britter

britter commented Oct 3, 2015

Copy link
Copy Markdown
Member

Can you please explain some more what problems you're running into without this fix? A test case that fails without your change but is successful with this change would help me to understand this proposal.

@britter

britter commented Oct 3, 2015

Copy link
Copy Markdown
Member

Placeholder JIRA ticket is https://issues.apache.org/jira/browse/CSV-158

@mirasrael

Copy link
Copy Markdown
Contributor Author

You may not be sure buffer in call same as for previous read call. So you can just create new buffer without any initialization and call read method with non-zero offset. In this case character at position i-1 has undefined value. So you should check against offset for lastChar instead of zero.

@garydgregory

Copy link
Copy Markdown
Member

Can you provide a unit test patch that shows the main code failing and then passing with this fix?

@mirasrael

Copy link
Copy Markdown
Contributor Author

Without the fix getLineNumber method returns 3.

@britter

britter commented Oct 8, 2015

Copy link
Copy Markdown
Member

@mirasrael thank you for the test. Things are getting clearer now. How would a CSV file look like which the parser fails to parse because of this bug?

@mirasrael

Copy link
Copy Markdown
Contributor Author

Sorry. Its hard to remember where I face this bug, because I posted it year ago.

@britter

britter commented Oct 8, 2015

Copy link
Copy Markdown
Member

@mirasrael yes I understand this and I'm very thankful that you reported it in the first case. I'm just trying to find out what the implications of applying this patch is. :-)

@dota17

dota17 commented Feb 28, 2020

Copy link
Copy Markdown
Contributor

hi @britter after review the code,I think what @mirasrael means is that when use a new char[] buf and offset start from 5 in that way buf[0] to buf[4] are unspecified. so when i equals offset (that means i is 5) the expression (i > 0 ? buf[i - 1] : lastChar return buf[4] but what should return lastChar.

@garydgregory

Copy link
Copy Markdown
Member

@mirasrael
Please rebase on git master to we can see new build results.

@mirasrael mirasrael changed the base branch from trunk to master July 7, 2021 12:14
@mirasrael

Copy link
Copy Markdown
Contributor Author

Updated for master

@garydgregory garydgregory changed the title Fix eol checking for read array in ExtendedBufferedReader [CSV-158] Fix EOL checking for read array in ExtendedBufferedReader Jul 7, 2021
@garydgregory

Copy link
Copy Markdown
Member

@garydgregory garydgregory merged commit a6ca416 into apache:master Jul 7, 2021
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.

4 participants