[ 
https://issues.apache.org/jira/browse/ARTEMIS-2083?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16612693#comment-16612693
 ] 

ASF GitHub Bot commented on ARTEMIS-2083:
-----------------------------------------

Github user clebertsuconic commented on a diff in the pull request:

    https://github.com/apache/activemq-artemis/pull/2308#discussion_r217176110
  
    --- Diff: 
artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessage.java
 ---
    @@ -380,83 +395,63 @@ private synchronized void 
partialDecode(ReadableBuffer buffer) {
           decoder.setBuffer(buffer.rewind());
     
           _header = null;
    +      expiration = 0;
    +      headerEnds = 0;
    +      messagePaylodStart = 0;
           _deliveryAnnotations = null;
           _messageAnnotations = null;
           _properties = null;
           applicationProperties = null;
    -      Section section = null;
    +      appLocation = -1;
    +      deliveryAnnotationsPosition = -1;
     
           try {
    -         if (buffer.hasRemaining()) {
    -            section = (Section) decoder.readObject();
    -         }
    -
    -         if (section instanceof Header) {
    -            _header = (Header) section;
    -            headerEnds = buffer.position();
    -            messagePaylodStart = headerEnds;
    -            this.durable = _header.getDurable();
    -
    -            if (_header.getTtl() != null) {
    -               this.expiration = System.currentTimeMillis() + 
_header.getTtl().intValue();
    -            }
    -
    -            if (buffer.hasRemaining()) {
    -               section = (Section) decoder.readObject();
    -            } else {
    -               section = null;
    -            }
    -
    -         } else {
    -            // meaning there is no header
    -            headerEnds = 0;
    -         }
    -         if (section instanceof DeliveryAnnotations) {
    -            _deliveryAnnotations = (DeliveryAnnotations) section;
    -
    -            // Advance the start beyond the delivery annotations so they 
are not written
    -            // out on send of the message.
    -            messagePaylodStart = buffer.position();
    -
    -            if (buffer.hasRemaining()) {
    -               section = (Section) decoder.readObject();
    -            } else {
    -               section = null;
    -            }
    -         }
    -         if (section instanceof MessageAnnotations) {
    -            _messageAnnotations = (MessageAnnotations) section;
    -
    -            if (buffer.hasRemaining()) {
    -               section = (Section) decoder.readObject();
    -            } else {
    -               section = null;
    -            }
    -         }
    -         if (section instanceof Properties) {
    -            _properties = (Properties) section;
    -
    -            if (_properties.getAbsoluteExpiryTime() != null && 
_properties.getAbsoluteExpiryTime().getTime() > 0) {
    -               this.expiration = 
_properties.getAbsoluteExpiryTime().getTime();
    -            }
    -
    -            // We don't read the next section on purpose, as we will parse 
ApplicationProperties
    -            // lazily
    -            section = null;
    -         }
    -
    -         if (section instanceof ApplicationProperties) {
    -            applicationProperties = (ApplicationProperties) section;
    -         } else {
    -            if (buffer.hasRemaining()) {
    -               this.appLocation = buffer.position();
    +         while (buffer.hasRemaining()) {
    +            int constructorPos = buffer.position();
    +            TypeConstructor<?> constructor = decoder.readConstructor();
    +            if (Header.class.equals(constructor.getTypeClass())) {
    +               _header = (Header) constructor.readValue();
    +               headerEnds = messagePaylodStart = buffer.position();
    +               durable = _header.getDurable();
    +               if (_header.getTtl() != null) {
    +                  expiration = System.currentTimeMillis() + 
_header.getTtl().intValue();
    +               }
    +            } else if 
(DeliveryAnnotations.class.equals(constructor.getTypeClass())) {
    +               // Don't decode these as they are not used by the broker at 
all and are
    +               // discarded on send, mark for lazy decode if ever needed.
    +               constructor.skipValue();
    --- End diff --
    
    Is this a new API method?


> AMQP: Ensure message elements are not decoded unless needed
> -----------------------------------------------------------
>
>                 Key: ARTEMIS-2083
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-2083
>             Project: ActiveMQ Artemis
>          Issue Type: Improvement
>          Components: AMQP
>    Affects Versions: 2.6.3
>            Reporter: Timothy Bish
>            Assignee: Timothy Bish
>            Priority: Major
>             Fix For: 2.7.0
>
>
> With the right Message encoding the broker can mistakenly fully decode the 
> AMQP message body when it should ever be doing so unless converting to Core. 
> This can happen when no ApplicationProperties are present and a lazy decode 
> attempt happen or it can occur if the Message doesn't carry and Properties or 
> ApplicationProperties when the initial message partial decode happens.  
> Likewise the broker can in some cases decode the Application Properties when 
> they should only be decoded lazily. 
> We can also skip decode of any delivery annotations as they are never used by 
> the broker at the moment and we can lazy decode them later as needed.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to