From 9ddf5794dd6eb5222fc1cccceb7d27c7cbd9c785 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Thu, 20 Mar 2025 19:04:10 +0900 Subject: sandbox/vfs: implement proc_pid_mountinfo(5) parser Test cases are mostly taken from util-linux. This implementation is more correct and slightly faster than the one found in github:kubernetes/utils. Signed-off-by: Ophestra --- sandbox/vfs/mangle.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 sandbox/vfs/mangle.go (limited to 'sandbox/vfs/mangle.go') diff --git a/sandbox/vfs/mangle.go b/sandbox/vfs/mangle.go new file mode 100644 index 00000000..83aba589 --- /dev/null +++ b/sandbox/vfs/mangle.go @@ -0,0 +1,30 @@ +package vfs + +import "strings" + +func Unmangle(s string) string { + if !strings.ContainsRune(s, '\\') { + return s + } + + v := make([]byte, len(s)) + var ( + j int + c byte + ) + for i := 0; i < len(s); i++ { + c = s[i] + if c == '\\' && len(s) > i+3 && + (s[i+1] == '0' || s[i+1] == '1') && + (s[i+2] >= '0' && s[i+2] <= '7') && + (s[i+3] >= '0' && s[i+3] <= '7') { + c = ((s[i+1] - '0') << 6) | + ((s[i+2] - '0') << 3) | + (s[i+3] - '0') + i += 3 + } + v[j] = c + j++ + } + return string(v[:j]) +} -- cgit v1.3.1