Skip to content

Commit

Permalink
Fix stack overflow in Glob ordering
Browse files Browse the repository at this point in the history
This issue was reported in sbt/sbt#4970. The
isssu was that the glob ordering had an infinite loop in it when
a Root glob was compared to a FullFileGlob (which are created to convert
directory + fileFilter to Glob for legacy support). The reason this
hadn't been seen is because the play plugin is one of the few places
that creates sbt.internal.io.Source from single paths, which is from where
the Root globs (which are rarely a part of the watch globs) are coming.
This seems to be a side effect of play putting assets in the source
directory:
watchSources ++= {
    ((sourceDirectory in Compile).value ** "*" --- (sourceDirectory in Assets).value ** "*").get
},
is the setting that triggered the issue.
  • Loading branch information
eatkins committed Aug 21, 2019
1 parent 2022d63 commit f8dae12
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions io/src/main/scala/sbt/nio/file/Glob.scala
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,13 @@ object Glob {
case Root(leftRoot) =>
right match {
case Root(rightRoot) => leftRoot.compareTo(rightRoot)
case _: FullFileGlob => -1
case _ => -compare(right, left)
}
case FullFileGlob(leftBase, _, _) =>
right match {
case FullFileGlob(rightBase, _, _) => leftBase.compareTo(rightBase)
case _: Root => 1
case _ => -compare(right, left)
}
}
Expand Down
5 changes: 5 additions & 0 deletions io/src/test/scala/sbt/nio/GlobOrderingSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ class GlobOrderingSpec extends FlatSpec {
val nonRecursive = Glob(dir)
assert(Seq(nonRecursive, recursive).sorted == Seq(recursive, nonRecursive))
}
they should "not stack overflow" in IO.withTemporaryDirectory { dir =>
val exact = Glob(dir.toPath.resolve("foo"))
val fullFile = sbt.internal.nio.Globs(dir.toPath, true, sbt.io.HiddenFileFilter)
assert(Seq(exact, fullFile).sorted == Seq(exact, fullFile))
}
}

0 comments on commit f8dae12

Please sign in to comment.