Fix platform-specific std::length_error in WZ file parsing#8
Merged
ErwinsExpertise merged 3 commits intomasterfrom Nov 8, 2025
Merged
Fix platform-specific std::length_error in WZ file parsing#8ErwinsExpertise merged 3 commits intomasterfrom
ErwinsExpertise merged 3 commits intomasterfrom
Conversation
Co-authored-by: ErwinsExpertise <44278151+ErwinsExpertise@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix std::length_error in NoLifeStory
Add length validation to prevent std::length_error in WZ file parsing
Nov 8, 2025
Owner
|
@copilot This doesnt sound right because when compiling it on windows and running it we dont run into these issues. Something else must be happening |
The issue was platform-specific due to incorrect handling of string conversions and length limits. Applied the comprehensive fix from the original NoLifeDev repository: 1. Changed limit from 0x1ffff to std::numeric_limits<uint16_t>::max() (65535) 2. Return placeholder string instead of throwing exception (graceful degradation) 3. Fixed convert_str() to use correct char16_t conversion instead of wchar_t 4. Added length check in add_string() to prevent downstream issues 5. Changed locale include from <locale> to <clocale> for standard C++ locale 6. Moved length checks to occur after skip() to properly advance file position This matches the fix proven to work on macOS/Linux in the original repository. Co-authored-by: ErwinsExpertise <44278151+ErwinsExpertise@users.noreply.github.com>
Author
You're absolutely right. The issue was platform-specific. I've applied the proper fix from NoLifeDev/NoLifeStory PR NoLifeDev#39 (commit 2fe93be) which addresses multiple related problems:
This fix was proven to work on macOS/Linux in the original repository and addresses the platform-specific behavior you observed on Windows vs Linux. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Copilot
AI
changed the title
Add length validation to prevent std::length_error in WZ file parsing
Fix platform-specific std::length_error in WZ file parsing
Nov 8, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
read_enc_string()function in wztonx.cpp callsresize()on string buffers without validating lengths from untrusted WZ file input, causingstd::length_error: basic_string::_M_createcrashes on malformed files. This issue was platform-specific, occurring primarily on Linux/macOS but not on Windows due to differences in string handling and UTF-16 conversion behavior.Changes
Applied the comprehensive fix from NoLifeDev/NoLifeStory PR #39:
std::numeric_limits<uint16_t>::max()(65535 bytes) matching the NX file format specification, instead of 0x1ffffconvert_str()to useconvert.to_bytes(p_str)directly withchar16_tinstead of unsafewchar_treinterpret casting<locale>to<clocale>for better cross-platform compatibilityskip()to ensure file offset advances correctly before validationThis fix gracefully handles corrupted WZ files instead of crashing, improving robustness across all platforms while maintaining compatibility with the NX file format.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.