tp: fix handling of -1 slices in internal_layout

Change-Id: I63496f10e5b3238f9149b64d2db02b460fac6b3d
Fixed: 338059788
diff --git a/src/trace_processor/perfetto_sql/intrinsics/functions/layout_functions.cc b/src/trace_processor/perfetto_sql/intrinsics/functions/layout_functions.cc
index 3384376..4029384 100644
--- a/src/trace_processor/perfetto_sql/intrinsics/functions/layout_functions.cc
+++ b/src/trace_processor/perfetto_sql/intrinsics/functions/layout_functions.cc
@@ -16,6 +16,7 @@
 
 #include <cstddef>
 #include <cstdint>
+#include <limits>
 #include <queue>
 #include <vector>
 #include "perfetto/base/logging.h"
@@ -64,8 +65,10 @@
     size_t depth = SelectAvailableDepth(is_busy);
     // If the slice has an end and is not an instant, schedule this depth
     // to be marked available again when it ends.
-    if (dur > 0) {
-      slice_ends_.push({ts + dur, depth});
+    if (dur != 0) {
+      int64_t ts_end =
+          dur == -1 ? std::numeric_limits<int64_t>::max() : ts + dur;
+      slice_ends_.push({ts_end, depth});
     }
     last_depth_ = depth;
     return base::OkStatus();