Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Offset out of bounds #45

Open
ncordon opened this issue Jul 24, 2019 · 2 comments
Open

Offset out of bounds #45

ncordon opened this issue Jul 24, 2019 · 2 comments
Assignees

Comments

@ncordon
Copy link
Member

ncordon commented Jul 24, 2019

From bblfsh logs we got a message of offset out of bounds.

Example of files that triggered this error:

Source/WebCore/page/csp/ContentSecurityPolicy.h
gnu/lib/libg++/g++-include/File.h
gnu/lib/libg++/g++-include/stdio.h
lib/boost_1.60.0/boost/log/utility/functional/nop.hpp
@ncordon ncordon added the bug label Jul 24, 2019
@kuba-- kuba-- self-assigned this Aug 20, 2019
@kuba--
Copy link
Member

kuba-- commented Aug 20, 2019

It's the CDT's issue. It cannot handle ambiguities for ellipsis (...)in parameter declaration.
For instance following function (LocOffsetEnd: 19, LocOffsetStart: 0):

void foo(int&...);

takes various number of int references. In CDT ... notation is called ellipsis. A parser parses all tokens correctly but at the end it visits CPPASTAmbiguityResolver, which tries to resolve ambiguity, what calls CPPASTAmbiguousParameterDeclaration.doResolveAmbiguity.
This class is responsible for:

Handles ambiguities for ellipsis in parameter declaration.
template<typename... T> void function(T ...); // is T a parameter pack?

and it tries to adjustOffsets(dtor).
Unfortunately the function does not work well if we have any parameters next to the type (&, *).
Here is a snippet from adjustOffsets function:

final ASTNode first = (ASTNode) ptrOps[0];
final ASTNode last = (ASTNode) ptrOps[ptrOps.length - 1];
asNode.setOffsetAndLength(first.getOffset(), last.getOffset() + last.getLength());

We have only one param &, so the first and last point to the same node with offset 12 and length 1.
In my opinion the function setOffsetAndLength (which overwrites position) is called incorrectly, because the second parameter value (last.getOffset() + last.getLength()) points to the end offset, but the function signature is:

void setOffsetAndLength(int offset, int length)

so, now if we try to calculate the end offset it will be offset + length.
In our case original offset was 12, length 1, but after adjust the length was 12 + 1 = 13, so the end offset is 25, what in our case it goes out of bounds [0, 19]

               'Prop_Name': {
                  IASTClass: "CPPASTName",
                  LocOffsetEnd: 8,
                  LocOffsetStart: 5,
                  Name: "foo",
                    },
               'Prop_Parameters': [
                        {
                     DeclaresParameterPack: false,
                     IASTClass: "CPPASTDeclarator",
                     LocOffsetEnd: 25,        <---------------------- OUT OF BOUNDS
                     LocOffsetStart: 12,
                     'Prop_Name': {
                        IASTClass: "CPPASTName",
                        Name: "",
                            },

@kuba--
Copy link
Member

kuba-- commented Aug 21, 2019

@kuba-- kuba-- added the blocked label Aug 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants