From 571047a64a142f9adc1c16d02f90388f27fa026a Mon Sep 17 00:00:00 2001 From: Vladislav Belov Date: Thu, 10 Sep 2026 16:39:14 +0200 Subject: [PATCH] Adds explicit check for VFS create alignment --- source/lib/file/vfs/tests/test_vfs_real_path.h | 4 +++- source/lib/file/vfs/tests/test_vfs_util.h | 5 ++++- source/lib/file/vfs/vfs.cpp | 2 ++ source/lib/file/vfs/vfs.h | 3 +-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/source/lib/file/vfs/tests/test_vfs_real_path.h b/source/lib/file/vfs/tests/test_vfs_real_path.h index 393e37feed..1811d8b27d 100644 --- a/source/lib/file/vfs/tests/test_vfs_real_path.h +++ b/source/lib/file/vfs/tests/test_vfs_real_path.h @@ -22,6 +22,7 @@ #include "lib/self_test.h" +#include "lib/allocators/shared_ptr.h" #include "lib/file/file_system.h" #include "lib/file/vfs/vfs.h" #include "lib/os_path.h" @@ -80,7 +81,8 @@ public: createRealDir(TEST_FOLDER / "cache" / "some_folder"); createRealDir(TEST_FOLDER / "some_mod" / "cache" / "some_mod"); - std::shared_ptr buf(new u8(1)); + std::shared_ptr buf; + TS_ASSERT_OK(AllocateAligned(buf, 1, maxSectorSize)); g_VFS->Mount(L"", TEST_FOLDER / "some_mod" / "", 0, 0); diff --git a/source/lib/file/vfs/tests/test_vfs_util.h b/source/lib/file/vfs/tests/test_vfs_util.h index 0dc45e2756..3bc6cda926 100644 --- a/source/lib/file/vfs/tests/test_vfs_util.h +++ b/source/lib/file/vfs/tests/test_vfs_util.h @@ -22,6 +22,7 @@ #include "lib/self_test.h" +#include "lib/allocators/shared_ptr.h" #include "lib/file/file_system.h" #include "lib/file/vfs/vfs.h" #include "lib/file/vfs/vfs_path.h" @@ -76,7 +77,9 @@ public: void test_getPathnames() { - std::shared_ptr nodata(new u8); + std::shared_ptr nodata; + TS_ASSERT_OK(AllocateAligned(nodata, 1, maxSectorSize)); + g_VFS->CreateFile("test_file.txt", {nodata.get(), 0}); g_VFS->CreateFile("test_file2.txt", {nodata.get(), 0}); g_VFS->CreateFile("test_file3.txt", {nodata.get(), 0}); diff --git a/source/lib/file/vfs/vfs.cpp b/source/lib/file/vfs/vfs.cpp index 04bc362c13..7b871992f9 100644 --- a/source/lib/file/vfs/vfs.cpp +++ b/source/lib/file/vfs/vfs.cpp @@ -145,6 +145,8 @@ public: WARN_RETURN_STATUS_IF_ERR(st); + ENSURE(IsAligned(fileContents.data(), maxSectorSize)); + const PRealDirectory& realDirectory = directory->AssociatedDirectory(); const OsPath name = pathname.Filename(); RETURN_STATUS_IF_ERR(realDirectory->Store(name, fileContents)); diff --git a/source/lib/file/vfs/vfs.h b/source/lib/file/vfs/vfs.h index 5563340b70..6684c927b4 100644 --- a/source/lib/file/vfs/vfs.h +++ b/source/lib/file/vfs/vfs.h @@ -145,8 +145,7 @@ struct IVFS /** * Create a file with the given contents. * @param pathname - * @param fileContents - * @param size [bytes] of the contents, will match that of the file. + * @param fileContents the pointer must be aligned to maxSectorSize * @return Status. **/ virtual Status CreateFile(const VfsPath& pathname, std::span fileContents) = 0;