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

Offset out of bounds #45

Open
Open

Description

@ncordon

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

Activity

  1. self-assigned this
    on Aug 20, 2019
  2. kuba-- commented on Aug 20, 2019

    @kuba--
    Member

    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: "",
                                },
    
  3. kuba-- commented on Aug 21, 2019

    @kuba--
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions