[ 
https://issues.apache.org/jira/browse/AMQCPP-759?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Arjun Ray updated AMQCPP-759:
-----------------------------
    Description: 
The code involves a defective test for overflow. 
{color:#cccccc}        {color}{color:#c586c0}if{color}{color:#cccccc} 
({color}{color:#9cdcfe}max{color}{color:#cccccc} 
{color}{color:#d4d4d4}>{color}{color:#cccccc} 
{color}{color:#9cdcfe}result{color}{color:#cccccc}) {{color}
{color:#cccccc}            {color}{color:#c586c0}throw{color}{color:#cccccc} 
{color}{color:#4ec9b0}exceptions{color}{color:#cccccc}::{color}{color:#4ec9b0}NumberFormatException{color}{color:#cccccc}({color}{color:#569cd6}_{_}FILE{_}_{color}{color:#cccccc},
 {color}{color:#569cd6}_{_}LINE{_}_{color}{color:#cccccc},{color}
{color:#cccccc}                {color}{color:#ce9178}"Long::parseLong - Parsed 
value greater than max for radix."{color}{color:#cccccc});{color}
{color:#cccccc}        }{color}
The bug shows up when the code base is compiled with optimization turned on 
(typically, with -O2).  With that the compiler (gcc) assumes that overflow will 
not occur and therefore does not even check for it.  As a result, an exception 
is not thrown, which causes a unit test (which was expecting the exception for 
invalid input) to fail.  Without optimization, the overflow causes undefined 
behavior (according to the C++ standards), which in this particular case 
results in the unit test passing accidentally.

This bug occurs only with unusual inputs, but in theory should not be present 
at all with a correct implementation of overflow detection.  This issue has 
been discussed in some depth at
https://stackoverflow.com/questions/3944505/detecting-signed-overflow-in-c-c

  was:
The code involves a defective test for overflow. 
{color:#cccccc}        {color}{color:#c586c0}if{color}{color:#cccccc} 
({color}{color:#9cdcfe}max{color}{color:#cccccc} 
{color}{color:#d4d4d4}>{color}{color:#cccccc} 
{color}{color:#9cdcfe}result{color}{color:#cccccc}) {{color}
{color:#cccccc}            {color}{color:#c586c0}throw{color}{color:#cccccc} 
{color}{color:#4ec9b0}exceptions{color}{color:#cccccc}::{color}{color:#4ec9b0}NumberFormatException{color}{color:#cccccc}({color}{color:#569cd6}__FILE__{color}{color:#cccccc},
 {color}{color:#569cd6}__LINE__{color}{color:#cccccc},{color}
{color:#cccccc}                {color}{color:#ce9178}"Long::parseLong - Parsed 
value greater than max for radix."{color}{color:#cccccc});{color}
{color:#cccccc}        }{color}
The bug shows up when the code base is compiled with optimization turned on 
(typically, with -O2).  With that the compiler (gcc) assumes that overflow will 
not occur and therefore does not even check for it.  As a result, an exception 
is not thrown, which causes a unit test (which was expecting the exception for 
invalid input) to fail.  Without optimization, the overflow causes undefined 
behavior (according to the C++ standards), which in this particular case 
results in the unit test passing accidentally.

This bug occurs only with unusual inputs, but in theory should not be present 
at all with a correct implementation of overflow detection.


> src/main/decaf/lang/Long.cpp does not detect overflow properly
> --------------------------------------------------------------
>
>                 Key: AMQCPP-759
>                 URL: https://issues.apache.org/jira/browse/AMQCPP-759
>             Project: ActiveMQ C++ Client
>          Issue Type: Bug
>          Components: Decaf
>    Affects Versions: 3.9.0, 3.9.1, 3.9.2, 3.9.3, 3.9.4, 3.9.5
>            Reporter: Arjun Ray
>            Assignee: Timothy A. Bish
>            Priority: Major
>
> The code involves a defective test for overflow. 
> {color:#cccccc}        {color}{color:#c586c0}if{color}{color:#cccccc} 
> ({color}{color:#9cdcfe}max{color}{color:#cccccc} 
> {color}{color:#d4d4d4}>{color}{color:#cccccc} 
> {color}{color:#9cdcfe}result{color}{color:#cccccc}) {{color}
> {color:#cccccc}            {color}{color:#c586c0}throw{color}{color:#cccccc} 
> {color}{color:#4ec9b0}exceptions{color}{color:#cccccc}::{color}{color:#4ec9b0}NumberFormatException{color}{color:#cccccc}({color}{color:#569cd6}_{_}FILE{_}_{color}{color:#cccccc},
>  {color}{color:#569cd6}_{_}LINE{_}_{color}{color:#cccccc},{color}
> {color:#cccccc}                {color}{color:#ce9178}"Long::parseLong - 
> Parsed value greater than max for radix."{color}{color:#cccccc});{color}
> {color:#cccccc}        }{color}
> The bug shows up when the code base is compiled with optimization turned on 
> (typically, with -O2).  With that the compiler (gcc) assumes that overflow 
> will not occur and therefore does not even check for it.  As a result, an 
> exception is not thrown, which causes a unit test (which was expecting the 
> exception for invalid input) to fail.  Without optimization, the overflow 
> causes undefined behavior (according to the C++ standards), which in this 
> particular case results in the unit test passing accidentally.
> This bug occurs only with unusual inputs, but in theory should not be present 
> at all with a correct implementation of overflow detection.  This issue has 
> been discussed in some depth at
> https://stackoverflow.com/questions/3944505/detecting-signed-overflow-in-c-c



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to