Skip to content

Fix a stack overflow when saving a long XML attribute - #292

Open
peterswimm wants to merge 1 commit into
djdiskmachine:masterfrom
peterswimm:fix/xml-long-attribute
Open

peterswimm wants to merge 1 commit into
djdiskmachine:masterfrom
peterswimm:fix/xml-long-attribute

Conversation

@peterswimm

Copy link
Copy Markdown

Description

TinyXML writes the project through Tiny2NosStub's fprintf, which formatted every piece into a 256 byte stack buffer with vsprintf. An attribute longer than that, such as a sample with a very long file name, ran past it, overwriting the stack and leaving lgptsav.dat cut short mid-write.

Now it formats with vsnprintf, and prints anything longer into a heap buffer of the right size.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Built from master with this change and run on the device below.

Test Configuration:

  • Hardware: Anbernic RG35XX SP
  • Test steps: save a project holding an attribute longer than 256 characters (e.g. a sample with a ~250 character file name). Before the fix the save crashes or leaves the file cut short; after it, the project saves and loads back.

Checklist:

  • I have performed a self-review of my code
  • I have commented particularly in hard-to-understand areas
  • I have updated CHANGELOG (left for the maintainer to place under the next build)
  • I have updated docs/wiki/What-is-LittlePiggyTracker.md reflecting my changes (no user-facing change to document)
  • I have version bumped in sources/Application/Model/Project.h (will bump if asked)
  • My changes generate no new warnings (removes the vsprintf warning in Tiny2NosStub.cpp; checked on macOS)

An LLM (Claude) was used to help find the bug and write the patch; I read the diff and tested it myself.

TinyXML writes the project through Tiny2NosStub's fprintf, which
formatted every piece into a 256 byte stack buffer with vsprintf. An
attribute longer than that, such as a sample with a very long file
name, ran past it, overwriting the stack and leaving the project file
cut short mid-write.

Now it formats with vsnprintf, and prints anything longer into a heap
buffer of the right size.

Assisted-by: Claude (LLM)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant