• Bug#1104933: activemq: diff for NMU version 5.17.6+dfsg-1.1 (21/48)

    From Emmanuel Arias@1:229/2 to All on Sun Jun 1 01:20:01 2025
    [continued from previous message]

    ++ // We should get an exception from an invalid size value that is too large
    ++ // Test OpenWireFormat#unmarshal(ByteSequence) method
    ++ format.unmarshal(bss);
    ++ fail("Should have received an IOException");
    ++ } catch (IOException io) {
    ++ assertTrue(io.getMessage().contains("Estimated allocated buffer size"));
    ++ assertTrue(io.getMessage().contains("is larger than frame size"));
    ++ }
    ++ // Verify thread local is cleared even after exception
    ++ assertNull(format.getMarshallingContext());
    ++
    ++ try {
    ++ // We should get an exception from an invalid size value that is too large
    ++ // Test OpenWireFormat#unmarshal(DataInput) method
    ++ format.unmarshal(new DataInputStream(new NIOInputStream(
    ++ ByteBuffer.wrap(bss.toArray()))));
    ++ fail("Should have received an IOException");
    ++ } catch (IOException io) {
    ++ assertTrue(io.getMessage().contains("Estimated allocated buffer size"));
    ++ assertTrue(io.getMessage().contains("is larger than frame size"));
    ++ }
    ++ // Verify thread local is cleared even after exception
    ++ assertNull(format.getMarshallingContext());
    ++ }
    ++
    ++ // Verify MarshallingContext thread local is cleared where there is
    ++ // successful unmarshalling and no error. The other tests that check
    ++ // validation works if invalid size will validate the context is cleared ++ // when there is an error
    ++ @Test
    ++ public void testUnmarshalNoErrorClearContext() throws Exception {
    ++ var format = new OpenWireFormat();
    ++ ByteSequence bss = format.marshal(new ConnectionInfo());
    ++
    ++ // make sure context cleared after calling
    ++ // OpenWireFormat#unmarshal(ByteSequence) method
    ++ format.unmarshal(bss);
    ++ assertNull(format.getMarshallingContext());
    ++
    ++ // Make sure context cleared after calling
    ++ // OpenWireFormat#unmarshal(DataInput) method
    ++ format.unmarshal(new DataInputStream(new NIOInputStream(
    ++ ByteBuffer.wrap(bss.toArray()))));
    ++ assertNull(format.getMarshallingContext());
    ++ }
    ++
    ++ @Test
    + public void testOpenwireThrowableValidation() throws Exception {
    + // Create a format which will use loose encoding by default
    + // The code for handling exception creation is shared between both
    + // tight/loose encoding so only need to test 1
    +- OpenWireFormat format = new OpenWireFormat();
    +-
    +- // Override the marshaller map with a custom impl to purposely marshal a class type that is
    +- // not a Throwable for testing the unmarshaller
    +- Class<?> marshallerFactory = getMarshallerFactory();
    +- Method createMarshallerMap = marshallerFactory.getMethod("createMarshallerMap", OpenWireFormat.class);
    +- DataStreamMarshaller[] map = (DataStreamMarshaller[]) createMarshallerMap.invoke(marshallerFactory, format);
    +- map[ExceptionResponse.DATA_STRUCTURE_TYPE] = getExceptionMarshaller();
    +- // This will trigger updating the marshaller from the marshaller map with the right version
    +- format.setVersion(version);
    ++ var format = setupWireFormat(false);
    +
    + // Build the response and try to unmarshal which should give an IllegalArgumentExeption on unmarshall
    + // as the test marshaller should have encoded a class type that is not a Throwable
    +@@ -89,6 +172,23 @@
    + assertTrue(response.getException().getMessage().contains("is not assignable to Throwable"));
    + }
    +
    ++ private OpenWireFormat setupWireFormat(boolean tightEncoding) throws Exception {
    ++ // Create a format
    ++ OpenWireFormat format = new OpenWireFormat();
    ++ format.setTightEncodingEnabled(tightEncoding);
    ++
    ++ // Override the marshaller map with a custom impl to purposely marshal a bad size value
    ++ Class<?> marshallerFactory = getMarshallerFactory();
    ++ Method createMarshallerMap = marshallerFactory.getMethod("createMarshallerMap", OpenWireFormat.class);
    ++ DataStreamMarshaller[] map = (DataStreamMarshaller[]) createMarshallerMap.invoke(marshallerFactory, format);
    ++ map[ExceptionResponse.DATA_STRUCTURE_TYPE] = getExceptionMarshaller();
    ++ map[WireFormatInfo.DATA_STRUCTURE_TYPE] = getWireFormatInfoMarshaller();
    ++ map[PartialCommand.DATA_STRUCTURE_TYPE] = getPartialCommandMarshaller();
    ++ // This will trigger updating the marshaller from the marshaller map with the right version
    ++ format.setVersion(version);
    ++ return format;
    ++ }
    ++
    + static class NotAThrowable {
    + private String message;
    +
    +@@ -163,4 +263,127 @@
    + }
    + }
    +
    ++ // Create test marshallers for all non-legacy versions
    ++ // WireFormatInfo will test the bytesequence marshallers
    ++ protected DataStreamMarshaller getWireFormatInfoMarshaller() {
    ++ switch (version) {
    ++ case 12:
    ++ return proxyBadBufferCommand(new org.apache.activemq.openwire.v12.WireFormatInfoMarshaller());
    ++ case 11:
    ++ return proxyBadBufferCommand(new org.apache.activemq.openwire.v11.WireFormatInfoMarshaller());
    ++ case 10:
    ++ return proxyBadBufferCommand(new org.apache.activemq.openwire.v10.WireFormatInfoMarshaller());
    ++ case 9:
    ++ return proxyBadBufferCommand(new org.apache.activemq.openwire.v9.WireFormatInfoMarshaller());
    ++ case 1:
    ++ return proxyBadBufferCommand(new org.apache.activemq.openwire.v1.WireFormatInfoMarshaller());
    ++ default:
    ++ throw new IllegalArgumentException("Unknown OpenWire version of " + version);
    ++ }
    ++ }
    ++
    ++ // PartialCommand will test the byte array marshallers
    ++ protected DataStreamMarshaller getPartialCommandMarshaller() {
    ++ switch (version) {
    ++ case 12:
    ++ return proxyBadBufferCommand(new org.apache.activemq.openwire.v12.PartialCommandMarshaller());
    ++ case 11:
    ++ return proxyBadBufferCommand(new org.apache.activemq.openwire.v11.PartialCommandMarshaller());
    ++ case 10:
    ++ return proxyBadBufferCommand(new org.apache.activemq.openwire.v10.PartialCommandMarshaller());
    ++ case 9:
    ++ return proxyBadBufferCommand(new org.apache.activemq.openwire.v9.PartialCommandMarshaller());
    ++ case 1:
    ++ return proxyBadBufferCommand(new org.apache.activemq.openwire.v1.PartialCommandMarshaller());
    ++ default:
    ++ throw new IllegalArgumentException("Unknown OpenWire version of " + version);
    ++ }
    ++ }
    ++
    ++ protected static void badTightMarshalByteSequence(ByteSequence data, DataOutput dataOut,
    ++ BooleanStream bs) throws IOException {
    ++ if (bs.readBoolean()) {
    ++ // Write an invalid length that is much larger than it should be ++ dataOut.writeInt(data.getLength() * 10);
    ++ dataOut.write(data.getData(), data.getOffset(), data.getLength());
    ++ }
    ++ }
    ++
    ++ protected static void badLooseMarshalByteSequence(ByteSequence data, DataOutput dataOut)
    ++ throws IOException {

    [continued in next message]

    --- SoupGate-Win32 v1.05
    * Origin: you cannot sedate... all the things you hate (1:229/2)