[PR #2370] [MERGED] lseek: let the host OS set lseek errors #2682

Closed
opened 2026-02-27 22:00:51 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/shadps4-emu/shadPS4/pull/2370
Author: @mailwl
Created: 2/7/2025
Status: Merged
Merged: 3/24/2025
Merged by: @georgemoralis

Base: mainHead: fix_lseek_for_xna


📝 Commits (5)

  • 806913b Fix lseek(fd, -1, SEEK_SET) for XNA
  • 6fe7275 be sure, if seek really return error
  • b29a1ec refactoring
  • 27aa629 Merge remote-tracking branch 'origin/main' into fix_lseek_for_xna
  • 4fa9d8e let host os set lseek errors

📊 Changes

2 files changed (+1 additions, -14 deletions)

View changed files

📝 src/common/io_file.cpp (+0 -14)
📝 src/core/libraries/kernel/file_system.cpp (+1 -0)

📄 Description

In game Timespinner, the code:

    public AudioEngine(string settingsFile, TimeSpan lookAheadTime, string rendererId)
    {
        using (Stream input = TitleContainer.OpenStream(settingsFile))
        {
            using (BinaryReader reader = new BinaryReader(input))
            {
                // skip
                uint prcCurveOffset = reader.ReadUInt32(); // <-- here 0xFFFFFFFFu
                // skip
                reader.BaseStream.Seek((long)prcCurveOffset, SeekOrigin.Begin); <-- (long)prcCurveOffset == 4294967295 
                for (int index1 = 0; (long)index1 < (long)prcCurveCount; ++index1)  // <-- prcCurveCount = 0, never executes
                {
                       ///skip
                }
            }
        }
    }

bad C# u32>s64 conversion leads to huge offset, and in C-code it compares to (s32)(-1), too, which not equal (s64)(-1) and then crash.
But, as you may see, in C# code, result of Seek() to not checked at all, and even not used, so, we can pass needed result/error to C-code.
I did some other changes, which made the game playable, but i do not know, which helps, will make pr for it later


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/shadps4-emu/shadPS4/pull/2370 **Author:** [@mailwl](https://github.com/mailwl) **Created:** 2/7/2025 **Status:** ✅ Merged **Merged:** 3/24/2025 **Merged by:** [@georgemoralis](https://github.com/georgemoralis) **Base:** `main` ← **Head:** `fix_lseek_for_xna` --- ### 📝 Commits (5) - [`806913b`](https://github.com/shadps4-emu/shadPS4/commit/806913baf585ded75e0000c28da23a9663d01bb2) Fix lseek(fd, -1, SEEK_SET) for XNA - [`6fe7275`](https://github.com/shadps4-emu/shadPS4/commit/6fe72758dea496ecb36748ae0269c958c64c105f) be sure, if seek really return error - [`b29a1ec`](https://github.com/shadps4-emu/shadPS4/commit/b29a1ec397a44c0c5e4c38554ddacb40bfad8aab) refactoring - [`27aa629`](https://github.com/shadps4-emu/shadPS4/commit/27aa629ebb5801c35c7232952ceacf4d1d1d5097) Merge remote-tracking branch 'origin/main' into fix_lseek_for_xna - [`4fa9d8e`](https://github.com/shadps4-emu/shadPS4/commit/4fa9d8e18bb3c28b58c6590d2a34b64165caebc5) let host os set lseek errors ### 📊 Changes **2 files changed** (+1 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `src/common/io_file.cpp` (+0 -14) 📝 `src/core/libraries/kernel/file_system.cpp` (+1 -0) </details> ### 📄 Description In game Timespinner, the code: ```c# public AudioEngine(string settingsFile, TimeSpan lookAheadTime, string rendererId) { using (Stream input = TitleContainer.OpenStream(settingsFile)) { using (BinaryReader reader = new BinaryReader(input)) { // skip uint prcCurveOffset = reader.ReadUInt32(); // <-- here 0xFFFFFFFFu // skip reader.BaseStream.Seek((long)prcCurveOffset, SeekOrigin.Begin); <-- (long)prcCurveOffset == 4294967295 for (int index1 = 0; (long)index1 < (long)prcCurveCount; ++index1) // <-- prcCurveCount = 0, never executes { ///skip } } } } ``` bad C# u32>s64 conversion leads to huge offset, and in C-code it compares to (s32)(-1), too, which not equal (s64)(-1) and then crash. But, as you may see, in C# code, result of Seek() to not checked at all, and even not used, so, we can pass needed result/error to C-code. I did some other changes, which made the game playable, but i do not know, which helps, will make pr for it later --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 22:00:51 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/shadPS4#2682
No description provided.