public BuilderType mergeFrom(final ByteString data) throws InvalidProtocolBufferException {
   try {
     final CodedInputStream input = data.newCodedInput();
     mergeFrom(input);
     input.checkLastTagWas(0);
     return (BuilderType) this;
   } catch (InvalidProtocolBufferException e) {
     throw e;
   } catch (IOException e) {
     throw new RuntimeException(
         "Reading from a ByteString threw an IOException (should " + "never happen).", e);
   }
 }
Esempio n. 2
0
  private void assertFieldsInOrder(ByteString data) throws Exception {
    CodedInputStream input = data.newCodedInput();
    int previousTag = 0;

    while (true) {
      int tag = input.readTag();
      if (tag == 0) {
        break;
      }

      assertTrue(tag > previousTag);
      input.skipField(tag);
    }
  }
Esempio n. 3
0
  public void testMaliciousRecursion() throws Exception {
    ByteString data100 = makeRecursiveMessage(100).toByteString();
    ByteString data101 = makeRecursiveMessage(101).toByteString();

    assertMessageDepth(TestRecursiveMessage.parseFrom(data100), 100);

    try {
      TestRecursiveMessage.parseFrom(data101);
      fail("Should have thrown an exception!");
    } catch (InvalidProtocolBufferException e) {
      // success.
    }

    CodedInputStream input = data100.newCodedInput();
    input.setRecursionLimit(8);
    try {
      TestRecursiveMessage.parseFrom(input);
      fail("Should have thrown an exception!");
    } catch (InvalidProtocolBufferException e) {
      // success.
    }
  }