Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing input length checks at imap.imap.lib.convertor.Opendrive2Apollo.add_lane_boundary #86

Closed
xqgex opened this issue May 18, 2023 · 1 comment

Comments

@xqgex
Copy link

xqgex commented May 18, 2023

Version

$ python3 -m pip show imap_box | grep Version
Version: 0.1.6

Traceback

...
    segment.start_position.x = lane.left_boundary[0].x
IndexError: list index out of range
...
    segment.start_position.x = lane.center_line[0].x
IndexError: list index out of range
...
    segment.start_position.x = lane.right_boundary[0].x
IndexError: list index out of range

Fix

imap/imap/lib/convertor.py

Lines 205 to 223 in e4afa8f

# 1. left boundary
segment = pb_lane.left_boundary.curve.segment.add()
for point3d in lane.left_boundary:
point = segment.line_segment.point.add()
# lhd 2022/12/03 for 3D view
if global_var.get_element_value("enable_z_axis"):
point.x, point.y, point.z = point3d.x, point3d.y, point3d.z
else:
point.x, point.y = point3d.x, point3d.y
segment.s = 0
segment.start_position.x = lane.left_boundary[0].x
segment.start_position.y = lane.left_boundary[0].y
segment.start_position.z = lane.left_boundary[0].z
segment.length = pb_lane.length
pb_lane.left_boundary.length = pb_lane.length
pb_boundary_type = to_pb_boundary_type(lane.left_boundary_type)
boundary_type = pb_lane.left_boundary.boundary_type.add()
boundary_type.s = 0
boundary_type.types.append(pb_boundary_type)

imap/imap/lib/convertor.py

Lines 225 to 238 in e4afa8f

# 2. center line
segment = pb_lane.central_curve.segment.add()
for point3d in lane.center_line:
point = segment.line_segment.point.add()
# lhd 2022/12/03 for 3D view
if global_var.get_element_value("enable_z_axis"):
point.x, point.y, point.z = point3d.x, point3d.y, point3d.z
else:
point.x, point.y = point3d.x, point3d.y
segment.s = 0
segment.start_position.x = lane.center_line[0].x
segment.start_position.y = lane.center_line[0].y
segment.start_position.z = lane.center_line[0].z
segment.length = pb_lane.length

imap/imap/lib/convertor.py

Lines 240 to 258 in e4afa8f

# 3. right boundary
segment = pb_lane.right_boundary.curve.segment.add()
for point3d in lane.right_boundary:
point = segment.line_segment.point.add()
# lhd 2022/12/03 for 3D view
if global_var.get_element_value("enable_z_axis"):
point.x, point.y, point.z = point3d.x, point3d.y, point3d.z
else:
point.x, point.y = point3d.x, point3d.y
segment.s = 0
segment.start_position.x = lane.right_boundary[0].x
segment.start_position.y = lane.right_boundary[0].y
segment.start_position.z = lane.right_boundary[0].z
segment.length = pb_lane.length
pb_lane.right_boundary.length = pb_lane.length
pb_boundary_type = to_pb_boundary_type(lane.right_boundary_type)
boundary_type = pb_lane.right_boundary.boundary_type.add()
boundary_type.s = 0
boundary_type.types.append(pb_boundary_type)

Check if the list is empty.

Suggested fix

    # 1. left boundary
    if lane.left_boundary:
      segment = pb_lane.left_boundary.curve.segment.add()
      for point3d in lane.left_boundary:
        ...
      ...
      boundary_type.s = 0
      boundary_type.types.append(pb_boundary_type)
    # 2. center line
    if lane.center_line:
      segment = pb_lane.central_curve.segment.add()
      for point3d in lane.center_line:
        ...
      ...
      segment.length = pb_lane.length
    # 3. right boundary
    if lane.right_boundary:
      segment = pb_lane.right_boundary.curve.segment.add()
      for point3d in lane.right_boundary:
        ...
      ...
      boundary_type.s = 0
      boundary_type.types.append(pb_boundary_type)
@daohu527
Copy link
Owner

This scenario is too extreme, will there be a lane without a left_boundary?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants