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

Incorrect usage of StringBuilder in TransactionAwareBufferedWriter #3745

Closed
pstowski opened this issue Jul 14, 2020 · 8 comments
Closed

Incorrect usage of StringBuilder in TransactionAwareBufferedWriter #3745

pstowski opened this issue Jul 14, 2020 · 8 comments
Labels
for: backport-to-4.2.x Issues that will be back-ported to the 4.2.x line in: infrastructure type: bug
Milestone

Comments

@pstowski
Copy link

Method public void write(String str, int off, int len) of org.springframework.batch.support.transaction.TransactionAwareBufferedWriter
seems to be using java.lang.StringBuilder in wrong way:
according to documentation StringBuilder.append(java.lang.CharSequence,int,int)
third parameter is not length (as in append(char[],int,int)) but the end index of the subsequence.
this causes invalid parts of string are being appended and causes java.lang.IndexOutOfBoundsException when off > len

Using: spring-batch-infrastructure 4.2.4.RELEASE

@pstowski pstowski added status: waiting-for-triage Issues that we did not analyse yet type: bug labels Jul 14, 2020
@mrickly
Copy link

mrickly commented Oct 30, 2020

We ran into that bug too, via StaxEventItemWriter with the default transactional = true.

@mprcptbl
Copy link

mprcptbl commented Jan 7, 2021

Same problem, using StaxEventItemWriter.

@nfjcore
Copy link
Contributor

nfjcore commented Jan 19, 2021

I would like to start contributing to this project. This seems like a good issue to work on. Can someone provide steps how to reproduce the problem?

@fmbenhassine
Copy link
Contributor

@nfjcore You are welcome! Please check our Contributor Guidelines. I did not work on this issue yet to validate the bug report, but the best way to start is by trying to create a failing test that reproduces the problem. I would be happy to review any PR that contains such a test with a corresponding fix. Let me know if you want me to assign this issue to you.

@niels5789
Copy link

@benas Thank you for the reply. I've read the Contributor Guidelines. And like the issue to be assigned to me.

@mprcptbl
Copy link

@niels5789 I don't have a simple testcase for this right now but you should be able to reproduce this by generating XML output using StaxEventItemWriter with the default transactional=true (e.g. create a simple Spring Batch job to do this) when your input data contains any XML special characters like ampersand. less than, etc.

@fmbenhassine
Copy link
Contributor

In order to avoid any confusion about to whom this issue should be assigned, I'm not going to assign it to anyone. Everyone is welcome to contribute to the project. If a PR is opened for this bug, I will link it to this issue.

@timtebeek timtebeek mentioned this issue Feb 3, 2021
@fmbenhassine fmbenhassine linked a pull request Feb 4, 2021 that will close this issue
@fmbenhassine fmbenhassine added for: backport-to-4.2.x Issues that will be back-ported to the 4.2.x line in: infrastructure and removed status: waiting-for-triage Issues that we did not analyse yet labels Feb 4, 2021
@fmbenhassine fmbenhassine added this to the 4.3.2 milestone Feb 4, 2021
@fmbenhassine
Copy link
Contributor

Fixed in #3843 .

@fmbenhassine fmbenhassine changed the title Incorrect usage of StringBuilder Incorrect usage of StringBuilder in TransactionAwareBufferedWriter Mar 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: backport-to-4.2.x Issues that will be back-ported to the 4.2.x line in: infrastructure type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants