Panakotta00 / FicsIt-Networks

Control, Monitor, Manage and Automate your Satisfactory.
https://ficsit.app/mod/FicsItNetworks
GNU General Public License v3.0
155 stars 50 forks source link

[Crash] [EA] using long file names #275

Open derFreemaker opened 8 months ago

derFreemaker commented 8 months ago

In latest Version in Update 8

To Reproduce

  1. Build a computer with cpu, ram, eeprom, and an floppy or hard disk
  2. Run this code until crash (like 3 - 8 times):
    
    filesystem.initFileSystem('/dev')
    local drive = ''
    for _, child in pairs(filesystem.childs('/dev')) do
    if not (child == 'serial') then
        drive = child
        break
    end
    end
    if drive:len() < 1 then
    computer.beep(0.2)
    error('Unable to find filesystem to load on! Insert a drive or floppy.')
    return
    end
    filesystem.mount('/dev/' .. drive, '/')

local dirPath = "/Long/Long/Long/Long/Long/Long/Long/Long/Long/Long" .. "/Long/Long/Long/Long/Long/Long/Long/Long/Long/Long" .. "/Long/Long/Long/Long/Long/Long/Long/Long/Long/Long/File/"

filesystem.createDir(dirPath, true) local file = filesystem.open(dirPath .. "Path.txt", "w") file:write("foo") file:close()


## Expected behavior
error of some sort (like too long file path) or not at all

## Exception:
Mod Version: 0.3.16

Version: 211839, IsEditor: No, IsPerforceBuild: No, BuildConfiguration: Shipping, Launcher: Epic, NetMode: Listen Server, IsUsingMods: Yes Unhandled Exception: 0xe06d7363

KERNELBASE VCRUNTIME140 FactoryGame_FicsItNetworks_Win64_Shipping!std::_Throw_system_error_from_std_win_error() [C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\INCLUDE\chrono:64] FactoryGame_FicsItNetworks_Win64_Shipping!std::_Convert_wide_to_narrow<std::char_traits,std::allocator >() [C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\INCLUDE\chrono:85] FactoryGame_FicsItNetworks_Win64_Shipping!CodersFileSystem::WindowsFileWatcher::handleChangeEvent() [G:\Projects\Satisfactory\SatisfactoryModLoader\Plugins\FicsItNetworks\Source\FicsItNetworks\FicsItKernel\FicsItFS\Library\WindowsFileWatcher.cpp:75] FactoryGame_FicsItNetworks_Win64_Shipping!FFINKernelFSDevDevice::tickListeners() [G:\Projects\Satisfactory\SatisfactoryModLoader\Plugins\FicsItNetworks\Source\FicsItNetworks\FicsItKernel\FicsItFS\DevDevice.cpp:76] FactoryGame_FicsItNetworks_Win64_Shipping!UFINKernelSystem::Tick() [G:\Projects\Satisfactory\SatisfactoryModLoader\Plugins\FicsItNetworks\Source\FicsItNetworks\FicsItKernel\FicsItKernel.cpp:123] FactoryGame_FicsItNetworks_Win64_Shipping!AFINComputerCase::Factory_Tick() [G:\Projects\Satisfactory\SatisfactoryModLoader\Plugins\FicsItNetworks\Source\FicsItNetworks\Computer\FINComputerCase.cpp:146] FactoryGame_FactoryGame_Win64_Shipping!::operator()() [D:\BuildAgent\work\78a794e88763017d\UE4\Games\FactoryGame\Source\FactoryGame\Private\FGBuildableSubsystem.cpp:561] FactoryGame_FactoryGame_Win64_Shipping!ParallelForImpl::TParallelForData<TFunctionRef<void __cdecl(int)> >::Process() [D:\BuildAgent\work\78a794e88763017d\UE4\Engine\Source\Runtime\Core\Public\Async\ParallelFor.h:177] FactoryGame_FactoryGame_Win64_Shipping!TGraphTask<ParallelForImpl::TParallelForTask<TFunctionRef<void __cdecl(int)> > >::ExecuteTask() [D:\BuildAgent\work\78a794e88763017d\UE4\Engine\Source\Runtime\Core\Public\Async\TaskGraphInterfaces.h:886] FactoryGame_Core_Win64_Shipping!FTaskThreadAnyThread::ProcessTasksUntilQuit() [D:\BuildAgent\work\78a794e88763017d\UE4\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:887] FactoryGame_Core_Win64_Shipping!FTaskThreadBase::Run() [D:\BuildAgent\work\78a794e88763017d\UE4\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:541] FactoryGame_Core_Win64_Shipping!FRunnableThreadWin::Run() [D:\BuildAgent\work\78a794e88763017d\UE4\Engine\Source\Runtime\Core\Private\Windows\WindowsRunnableThread.cpp:86]


## Code in Question
```c++
void WindowsFileWatcher::handleChangeEvent(FILE_NOTIFY_INFORMATION* changeEvent) {
        std::wstring fname = std::wstring((const wchar_t*)&changeEvent->FileName, changeEvent->FileNameLength);
        std::replace(fname.begin(), fname.end(), L'\\', L'/');
        Path path = fs::path(fname).string();    // error here because of wide char to narrow char convertion
        bool isDir = fs::is_directory(realPath / path.str());
        NodeType type = (isDir) ? NT_Directory : NT_File;
        switch (changeEvent->Action) {
        case FILE_ACTION_ADDED:
            eventFunc(0, type, path, Path());
            break;
        case FILE_ACTION_REMOVED:
            eventFunc(1, type, path, Path());
            break;
        case FILE_ACTION_MODIFIED:
            eventFunc(2, type, path, Path());
            break;
        case FILE_ACTION_RENAMED_NEW_NAME:
            eventFunc(3, type, path, fs::path(oldNameBufString).string());
            break;
        case FILE_ACTION_RENAMED_OLD_NAME:
            oldNameBufString = fname;
            break;
        }
    }

Source Code of Version: 0.3.16: