-
Notifications
You must be signed in to change notification settings - Fork 52
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
Custom buffer size ignored when adding BerTlv to BerTlvBuilder #13
Comments
I now understood that what I wanted to do was rather this: BerTlvBuilder berTlvBuilder = BerTlvBuilder.from(myBerTlv); Anyhow, this leaves no possibility to configure a custom buffer size. With elements over 5120 bytes (and I do have to handle those), it will lead to the exception posted above. |
Hi, Here is the tests for your issue: new BerTlvBuilder(null, new byte[bufferSize], 0, bufferSize); @Test
public void test_large_value_with_error() {
try {
BerTlvBuilder builder = new BerTlvBuilder();
builder.addBytes(new BerTag(0x82), new byte[6 * 1024]);
Assert.fail("Should throw ArrayIndexOutOfBoundsException because default buffer size is 5KB");
} catch (ArrayIndexOutOfBoundsException e) {
Assert.assertNull(e.getMessage());
}
}
@Test
public void test_large_value() {
final int sixKilobytes = 6 * 1024;
final int tagLength = 1;
final int valueLength = 3;
final int bufferSize = sixKilobytes + tagLength + valueLength;
BerTlvBuilder builder = new BerTlvBuilder(null, new byte[bufferSize], 0, bufferSize);
builder.addBytes(new BerTag(0x82), new byte[sixKilobytes]);
byte[] bytes = builder.buildArray();
Assert.assertEquals(bufferSize, bytes.length);
} It seems that we can use large buffer size for elements more the 5kb. |
Hi, thanks for your response. As far as I can see, you use the A test like this should lead to the error (I did not compile or test this code, just trying to give the idea):
|
I tried the test code I posted and found out that it did not reproduce the problem, because the BerTlv was not constructed. I created a pull request with a test reproducing the problem and proposing a solution: #14 |
…fer-size #13: Add possibility to add large constructed TLV elements to BerTlvBuilder
The following code will lead to an error, if myBerTlv has a value that has over 5120 bytes:
The exception I got was:
When using the
addBerTlv
method, the code eventually callspublic BerTlvBuilder(BerTag aTemplate)
, a method that overwrites the custom buffer with the default settings.The text was updated successfully, but these errors were encountered: