Skip to content

KAFKA-10574: Fix infinite loop in Values::parseString - #9375

Merged
rhauch merged 2 commits into
apache:trunkfrom
C0urante:kafka-10574
Oct 12, 2020
Merged

KAFKA-10574: Fix infinite loop in Values::parseString#9375
rhauch merged 2 commits into
apache:trunkfrom
C0urante:kafka-10574

Conversation

@C0urante

@C0urante C0urante commented Oct 5, 2020

Copy link
Copy Markdown
Contributor

Jira

The special byte sequence 0xEF, 0xBF, 0xBF, when parsed as a UTF-8 string, causes the StringCharacterIterator to return CharacterIterator.DONE from its next(), current(), and other similar methods. This caused an infinite loop in the Values class whenever that byte sequence was encountered.

The fix is pretty simple. To see if we're at the end of a string, we compare StandardCharacterIterator::getIndex to StandardCharacterIterator::getEndIndex, instead of comparing the last-read character to CharacterIterator.DONE (since that character may occur in strings that we're parsing).

I've added a unit test that replicates this bug (when the fix in the Values class is not present). I gave it a timeout of five seconds in case someone accidentally re-creates the infinite loop in order to save some time and potential confusion.

All existing unit tests for the Values class pass with this change.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@gharris1727 gharris1727 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@C0urante

C0urante commented Oct 5, 2020

Copy link
Copy Markdown
Contributor Author

@rhauch @kkonstantine can one of you take a look?

@kkonstantine kkonstantine left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. The fixes makes sense to me but I'm not intimately familiar with this class.
@rhauch, any concerns with the new check?

@C0urante I'd like to ask for a comment to the test so it's not as cryptic as assuming what these bytes mean for the given encoding.

Comment thread connect/api/src/test/java/org/apache/kafka/connect/data/ValuesTest.java Outdated

@kkonstantine kkonstantine left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fyi: jobs fail with checkstyle errors

@kkonstantine kkonstantine left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Need to fix checkstyle before merging.

@C0urante

C0urante commented Oct 5, 2020

Copy link
Copy Markdown
Contributor Author

Thanks @kkonstantine, I've added a comment and addressed the Checkstyle issues.

@rhauch rhauch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, pending a green build. Thanks, @C0urante.

@kkonstantine kkonstantine left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM after the latest fixes

@C0urante

C0urante commented Oct 8, 2020

Copy link
Copy Markdown
Contributor Author

Hi @rhauch @kkonstantine, this PR has been approved, all merge conflicts have been resolved, and every build is green. Would it be possible to merge sometime soon so that it can be backported to bug fix releases and avoid accruing merge conflicts in case the files touched here are modified in other PRs? Thanks!

@rhauch
rhauch merged commit 0a93d2b into apache:trunk Oct 12, 2020
@C0urante
C0urante deleted the kafka-10574 branch October 12, 2020 16:45
rhauch pushed a commit that referenced this pull request Oct 12, 2020
Fix infinite loop in Values::parseString

Author: Chris Egerton <chrise@confluent.io>
Reviewers: Konstantine Karantasis <konstantine@confluent.io>, Randall Hauch <rhauch@gmail.com>
rhauch pushed a commit that referenced this pull request Oct 12, 2020
Fix infinite loop in Values::parseString

Author: Chris Egerton <chrise@confluent.io>
Reviewers: Konstantine Karantasis <konstantine@confluent.io>, Randall Hauch <rhauch@gmail.com>
rhauch pushed a commit that referenced this pull request Oct 12, 2020
Fix infinite loop in Values::parseString

Author: Chris Egerton <chrise@confluent.io>
Reviewers: Konstantine Karantasis <konstantine@confluent.io>, Randall Hauch <rhauch@gmail.com>
rhauch pushed a commit that referenced this pull request Oct 12, 2020
Fix infinite loop in Values::parseString

Author: Chris Egerton <chrise@confluent.io>
Reviewers: Konstantine Karantasis <konstantine@confluent.io>, Randall Hauch <rhauch@gmail.com>
rhauch pushed a commit that referenced this pull request Oct 12, 2020
Fix infinite loop in Values::parseString

Author: Chris Egerton <chrise@confluent.io>
Reviewers: Konstantine Karantasis <konstantine@confluent.io>, Randall Hauch <rhauch@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants