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

why parse function only parsed 100 tlv? #20

Open
royzhao opened this issue Nov 16, 2021 · 4 comments
Open

why parse function only parsed 100 tlv? #20

royzhao opened this issue Nov 16, 2021 · 4 comments

Comments

@royzhao
Copy link

royzhao commented Nov 16, 2021

for(int i=0; i<100; i++) {
ParseResult result = parseWithResult(0, aBuf, offset, aLen-offset);
tlvs.add(result.tlv);

if(result.offset>=aOffset+aLen) {
    break;
}

offset = result.offset;

}

i think that code is better

int curOffset;
do {
ParseResult result = parseWithResult(0, aBuf, offset, aLen-offset);
tlvs.add(result.tlv);

  if(result.offset>=aOffset+aLen) {
      break;
  }
  curOffset = result.offset;

  offset = result.offset;

} while (curOffset<aOffset+aLen);

@IonutNegru87
Copy link

Wondering about this also - is this just to avoid very long parses? That magic number of 100 does not really make sense.

@eximius313
Copy link

simple:

    int offset = aOffset;
    do {
      final ParseResult result =  parseWithResult(0, aBuf, offset, aLen-offset);

      tlvs.add(result.tlv);
      offset = result.offset;
    } while(offset < aOffset+aLen);

passes all the tests

@martinpaljak
Copy link

it's usually about not having unbound loops on possibly unverified input.

@eximius313
Copy link

fair point. But this could be left as a setting

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

No branches or pull requests

4 participants