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

ASF GitHub Bot commented on ORC-314:
------------------------------------

GitHub user stiga-huang opened a pull request:

    https://github.com/apache/orc/pull/226

    ORC-314: Check scale range when parsing decimals

    The scale of decimals may be out of range in corrupt files. We should check 
this to avoid crashing.
    The attached file in the JIRA can reproduce this bug.

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

    $ git pull https://github.com/stiga-huang/orc check-scale-range

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

    https://github.com/apache/orc/pull/226.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 #226
    
----
commit e288b00e777133d161ab641c544f193f37dcacb6
Author: stiga-huang <huangquanlong@...>
Date:   2018-03-05T01:51:30Z

    ORC-314: Check scale range when parsing decimals

----


> C++ Reader crash for out of range scale in parsing decimals
> -----------------------------------------------------------
>
>                 Key: ORC-314
>                 URL: https://issues.apache.org/jira/browse/ORC-314
>             Project: ORC
>          Issue Type: Bug
>          Components: C++
>    Affects Versions: 1.4.3
>            Reporter: Quanlong Huang
>            Priority: Major
>         Attachments: decimal_ill_scale.orc
>
>
> The c++ reader crash in parsing the attached file. It's a corrupt orc file 
> with decimal values.
> {code}
> $ build/tools/src/orc-scan decimal_ill_scale.orc 
> Floating point exception (core dumped)
> {code}
> This is a devided-by-zero error:
> {code}
> Core was generated by `build/tools/src/orc-scan decimal_ill_scale.orc'.
> Program terminated with signal SIGFPE, Arithmetic exception.
> #0  0x0000000000896c0d in orc::Decimal64ColumnReader::readInt64 
> (this=0x1010120, value=@0x101aa60: 2222, currentScale=95) at 
> /mnt/volume1/orc/c++/src/ColumnReader.cc:1177
> 1177            value /= POWERS_OF_TEN[currentScale - scale];
> (gdb) bt
> #0  0x0000000000896c0d in orc::Decimal64ColumnReader::readInt64 
> (this=0x1010120, value=@0x101aa60: 2222, currentScale=95) at 
> /mnt/volume1/orc/c++/src/ColumnReader.cc:1177
> #1  0x0000000000895700 in orc::Decimal64ColumnReader::next (this=0x1010120, 
> rowBatch=..., numValues=5, notNull=0x0) at 
> /mnt/volume1/orc/c++/src/ColumnReader.cc:1268
> #2  0x0000000000893880 in orc::StructColumnReader::next (this=0xff9720, 
> rowBatch=..., numValues=5, notNull=0x0) at 
> /mnt/volume1/orc/c++/src/ColumnReader.cc:813
> #3  0x0000000000833e86 in orc::RowReaderImpl::next (this=0x10044b0, data=...) 
> at /mnt/volume1/orc/c++/src/Reader.cc:832
> #4  0x000000000082d274 in scanFile (out=..., filename=0x7ffc132d3755 
> "decimal_ill_scale.orc", batchSize=1024) at 
> /mnt/volume1/orc/tools/src/FileScan.cc:39
> #5  0x000000000082d4c5 in main (argc=1, argv=0x7ffc132d1940) at 
> /mnt/volume1/orc/tools/src/FileScan.cc:84
> (gdb) p currentScale
> $1 = 95
> (gdb) p scale
> $2 = 0
> {code}
> 95 is out of the length of the POWERS_OF_TEN array. So it gets value 0 
> unexpectedly.
> {code}
>   class Decimal64ColumnReader: public ColumnReader {
>   public:
>     static const uint32_t MAX_PRECISION_64 = 18;
>     static const uint32_t MAX_PRECISION_128 = 38;
>     static const int64_t POWERS_OF_TEN[MAX_PRECISION_64 + 1];
> {code}
> We should check the range of currentScale in Decimal64ColumnReader::readInt64 
> to avoid this.



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

Reply via email to