From 676691ce6d5eb4f400612529b02cdb87cc33bda1 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Fri, 28 Jan 2022 10:54:07 +0000 Subject: [PATCH] Fix: Avoid a false type assertion in the inmemory driver This issue was discovered by the following fuzzer: https://github.com/cncf/cncf-fuzzing/blob/main/projects/distribution/inmemory_fuzzer.go#L24 Signed-off-by: Milos Gajdos --- registry/storage/driver/inmemory/mfs.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/registry/storage/driver/inmemory/mfs.go b/registry/storage/driver/inmemory/mfs.go index 9a2865f95..8134e1cce 100644 --- a/registry/storage/driver/inmemory/mfs.go +++ b/registry/storage/driver/inmemory/mfs.go @@ -244,11 +244,16 @@ func (d *dir) delete(p string) error { return errNotExists } - if _, ok := parent.(*dir).children[filename]; !ok { + parentDir, ok := parent.(*dir) + if !ok { + return errIsNotDir + } + + if _, ok := parentDir.children[filename]; !ok { return errNotExists } - delete(parent.(*dir).children, filename) + delete(parentDir.children, filename) return nil }