diff --git a/app/src/main/cpp/skyline/services/am/storage/IStorageAccessor.cpp b/app/src/main/cpp/skyline/services/am/storage/IStorageAccessor.cpp index f88150bb..e6f1ac0a 100644 --- a/app/src/main/cpp/skyline/services/am/storage/IStorageAccessor.cpp +++ b/app/src/main/cpp/skyline/services/am/storage/IStorageAccessor.cpp @@ -14,11 +14,12 @@ namespace skyline::service::am { Result IStorageAccessor::Write(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { auto offset{request.Pop()}; - auto size{std::min(static_cast(request.inputBuf.at(0).size()), static_cast(parent->content.size()) - offset)}; - if (offset > parent->content.size()) + if (offset < 0 || offset > parent->content.size()) return result::OutOfBounds; + auto size{std::min(static_cast(request.inputBuf.at(0).size()), static_cast(parent->content.size()) - offset)}; + if (size) span(parent->content).copy_from(request.inputBuf.at(0), size); @@ -27,12 +28,13 @@ namespace skyline::service::am { Result IStorageAccessor::Read(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { auto offset{request.Pop()}; - auto size{std::min(static_cast(request.outputBuf.at(0).size()), static_cast(parent->content.size()) - offset)}; - if (offset > parent->content.size()) + if (offset < 0 || offset > parent->content.size()) return result::OutOfBounds; - if (size > 0) + auto size{std::min(static_cast(request.outputBuf.at(0).size()), static_cast(parent->content.size()) - offset)}; + + if (size) request.outputBuf.at(0).copy_from(span(parent->content.data() + offset, size)); return {};