diff --git a/src/main/scala/li/cil/oc/server/fs/Buffered.scala b/src/main/scala/li/cil/oc/server/fs/Buffered.scala index fd4fbf1b4..c09c83d82 100644 --- a/src/main/scala/li/cil/oc/server/fs/Buffered.scala +++ b/src/main/scala/li/cil/oc/server/fs/Buffered.scala @@ -14,6 +14,8 @@ trait Buffered extends OutputStreamFileSystem { private val deletions = mutable.Map.empty[String, Long] + protected def isValidFilename(name: String) = true + // ----------------------------------------------------------------------- // override def delete(path: String) = { @@ -37,7 +39,7 @@ trait Buffered extends OutputStreamFileSystem { override def load(nbt: NBTTagCompound) = { def recurse(path: String, directory: io.File) { makeDirectory(path) - for (child <- directory.listFiles()) { + for (child <- directory.listFiles() if isValidFilename(child.getName)) { val childPath = path + child.getName val childFile = new io.File(directory, child.getName) if (child.isDirectory) { diff --git a/src/main/scala/li/cil/oc/server/fs/FileSystem.scala b/src/main/scala/li/cil/oc/server/fs/FileSystem.scala index 2c48b6bb2..86422ab36 100644 --- a/src/main/scala/li/cil/oc/server/fs/FileSystem.scala +++ b/src/main/scala/li/cil/oc/server/fs/FileSystem.scala @@ -158,6 +158,8 @@ object FileSystem extends api.detail.FileSystemAPI { // accordingly before the path is passed to the file system. private val invalidChars = """\:*?"<>|""".toSet + override protected def isValidFilename(name: String) = !name.exists(invalidChars.contains) + override def makeDirectory(path: String) = super.makeDirectory(validatePath(path)) override protected def openOutputHandle(id: Int, path: String, mode: Mode) = super.openOutputHandle(id, validatePath(path), mode) @@ -168,7 +170,7 @@ object FileSystem extends api.detail.FileSystemAPI { } private def validatePath(path: String) = { - if (path.exists(invalidChars.contains)) { + if (!isValidFilename(path)) { throw new java.io.IOException("path contains invalid characters") } path