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

ASF GitHub Bot commented on AMQ-5381:
-------------------------------------

GitHub user letM3in opened a pull request:

    https://github.com/apache/activemq/pull/47

    https://issues.apache.org/jira/browse/AMQ-5381

    Modified ActiveMQBytesMessage so that the 'compressed' flag is only set 
when the 'content' is stored, instead of whenever writing is initialized.  This 
resolves https://issues.apache.org/jira/browse/AMQ-5381
    
    Added unit test to test for AMQ-5381 condition.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/letM3in/activemq trunk

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/activemq/pull/47.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #47
    
----
commit ebc4304f45293f72cab4aeab881d38c0d53ad47d
Author: Brian D. Johnson <[email protected]>
Date:   2014-10-03T16:56:49Z

    https://issues.apache.org/jira/browse/AMQ-5381 - Fix ActiveMQBytesMessage's 
'compressed' flag so that it is only set when the message content is actually 
compressed/stored

commit 63722a45d8f0827c762f3f880569bffaa9be7901
Author: Brian D. Johnson <[email protected]>
Date:   2014-10-10T11:56:55Z

    Merge remote-tracking branch 'upstream/trunk' into trunk

----


> ActiveMQBytesMessage mishandles restoration of old message contents
> -------------------------------------------------------------------
>
>                 Key: AMQ-5381
>                 URL: https://issues.apache.org/jira/browse/AMQ-5381
>             Project: ActiveMQ
>          Issue Type: Bug
>          Components: JMS client
>    Affects Versions: 5.9.1, 5.10.0
>            Reporter: Brian D. Johnson
>              Labels: easyfix
>
> Changes made in ActiveMQ 5.9.1, AMQ-4887, 
> [[cb5c29d02d02dc7f7fa4f5c1a97bd2a59078bccd|https://github.com/apache/activemq/commit/cb5c29d02d02dc7f7fa4f5c1a97bd2a59078bccd#diff-c0b18b235652457c810fe322bce65e31]]
>  introduced a bug in {{ActiveMQBytesMessage}} which results in a 
> {{java.util.zip.ZipException: incorrect header check}} being thrown at 
> {{org.apache.activemq.command.ActiveMQBytesMessage.restoreOldContent(ActiveMQBytesMessage.java:883)}}
>  when a consumer attempts to reuse a received {{ActiveMQBytesMessage}}.
> This bug is triggered under a unique set of circumstances:
> # A message is published by a JMS client with compression *_disabled_* on its 
> {{ActiveMQConnection}}
> # The message is consumed by a JMS client with compression *_enabled_* on its 
> {{ActiveMQConnection}}
> # The JMS consumer makes the received message writable in order to modify and 
> reuse it:
> {code}
> message.setReadOnlyProperties(false);
> message.setReadOnlyBody(false);
> {code}
> # The JMS consumer modifies the message, triggering a call to 
> {{ActiveMQBytesMessage.initializeWriting()}}
> The problem within {{ActiveMQBytesMessage.initializeWriting()}} is that the 
> method determines whether the message should be compressed _when it is 
> published_ (based on its current connection) BEFORE it has restored the 
> message's original content.  In the example above, the message's original 
> {{compressed}} flag is changed from {{false}} to {{true}}, resulting in 
> {{restoreOldContent()}} trying to decompress message contents which were 
> never compressed.
> {code}
> private void initializeWriting() throws JMSException {
>         checkReadOnlyBody();
>         if (this.dataOut == null) {
>             this.bytesOut = new ByteArrayOutputStream();
>             OutputStream os = bytesOut;
>             this.dataOut = new DataOutputStream(os);
>         }
>         // should compression be used when publishing this message??
>         ActiveMQConnection connection = getConnection();
>         if (connection != null && connection.isUseCompression()) {
>             compressed = true;
>         }
>         // restore the message's old content
>         restoreOldContent();
> }
> {code}
> A simple solution would be to move the {{restoreOldContent()}} method call 
> before the {{connection.isUseCompression()}} conditional in 
> {{ActiveMQBytesMessage.initializeWriting()}}.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to