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

Fix buffer overflow when creating bounding boxes #152

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/loader/gtfs/shape_prepare.cc
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ void assign_bounding_boxes(timetable const& tt,
auto const& bboxes = res.segment_bboxes_;
if (!bboxes.empty()) {
for (auto const [i, bbox] : utl::enumerate(bboxes)) {
segment_bboxes[i + cista::to_idx(absolute_range.from_)].extend(
bbox);
segment_bboxes.at(i + cista::to_idx(absolute_range.from_))
.extend(bbox);
}
is_trivial = false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/loader/gtfs/stop_time.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ void read_stop_times(timetable& tt,
t->requires_sorting_ |= (!t->seq_numbers_.empty() &&
t->seq_numbers_.back() > *s.stop_sequence_);

t->seq_numbers_.emplace_back(*s.stop_sequence_);
t->stop_seq_.push_back(stop{stops.at(s.stop_id_->view()), in_allowed,
out_allowed, in_allowed, out_allowed}
.value());
t->seq_numbers_.emplace_back(*s.stop_sequence_);
t->event_times_.emplace_back(
stop_events{.arr_ = arrival_time, .dep_ = departure_time});
if (store_distances) {
Expand Down
27 changes: 27 additions & 0 deletions test/loader/gtfs/service_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ X,20191027,1
std::string{
R"(route_id,agency_id,route_short_name,route_long_name,route_desc,route_type
A,DB,1337,Long Name,Route Description,3
B,DB,99,MisMatch,A route containing a stop without an entry in stops.txt,3
)"}},
{path{kTripsFile},
std::string{R"(route_id,service_id,trip_id,trip_headsign,block_id
A,X,X1,Trip X,
B,X,X2,Stop ID missing,
)"}},
{path{kStopTimesFile},
std::string{
Expand All @@ -56,6 +58,9 @@ X1,00:59:00,01:59:00,B,2,0,0
X1,02:00:00,02:01:00,C,3,0,0
X1,02:59:00,03:00:00,D,4,0,0
X1,03:30:00,03:30:00,E,5,0,0
X2,00:00:00,00:00:00,A,1,0,0
X2,00:30:00,00:30:00,missing,2,0,0
X2,01:00:00,01:00:00,D,3,0,0
)"}}}};
}

Expand Down Expand Up @@ -118,4 +123,26 @@ TEST(gtfs, local_to_unix_trip_test) {
EXPECT_EQ("2019-03-31T01:00+01:00", iso(t_march->first, 2, event_type::kArr));
EXPECT_EQ("2019-03-31T01:59+01:00", iso(t_march->first, 3, event_type::kArr));
EXPECT_EQ("2019-03-31T03:00+02:00", iso(t_march->first, 3, event_type::kDep));

// Route with stop_id not contained in 'stops.txt'
{
auto const t_mm = get_ref_transport(tt, trip_id{"X2", source_idx_t{0}},
2019_y / March / 30, true);
ASSERT_TRUE(t_mm.has_value());
constexpr auto kExpectedStops = 2U;
auto const r = tt.transport_route_[t_mm->first.t_idx_];
auto trip_count = 0U;

EXPECT_EQ(kExpectedStops, tt.route_location_seq_[r].size());
for (auto const transport_idx : tt.route_transport_ranges_[r]) {
for (auto const& merged_trip_idx :
tt.transport_to_trip_section_[transport_idx]) {
for (auto const& trip_idx : tt.merged_trips_[merged_trip_idx]) {
EXPECT_EQ(kExpectedStops, tt.trip_stop_seq_numbers_[trip_idx].size());
++trip_count;
}
}
}
EXPECT_TRUE(trip_count > 0U);
}
}
Loading