+
Skip to content

Conversation

WangSimiao2000
Copy link
Contributor

This PR adds a minimal reproducible example that triggers a dst buffer overflow inside
src/renderer/sw_engine/tvgSwRasterTexmap.h::_apply() under certain transformation matrices.

The test continuously applies random transformations (translate, scale, rotate, shear)
to a picture each frame, which helps to expose corner cases in texture mapping and matrix-based rasterization.

When using specific affine transform matrices with large shear and rotation factors,
the dst pointer will overflow in _apply().

Example crash matrix:

Matrix:
[ 0.572866, -4.431353, 336.605835 ]
[ 5.198910, -0.386219, 30.710693 ]
[ 0.000000, 0.000000, 1.000000 ]

Introduces a new example that applies randomized affine transforms
(translate, scale, rotate, shear) to an image each frame to stress
test rendering edge cases and expose potential issues in texture
mapping. Includes a known crash-inducing matrix for targeted
reproduction and debugging.

Signed-off-by: wangsimiao1 <wangsimiao1@xiaomi.com>
@Copilot Copilot AI review requested due to automatic review settings October 11, 2025 05:44
@github-actions github-actions bot added the example Sample Code label Oct 11, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a stress test to reproduce a buffer overflow issue in the ThorVG software rasterizer's texture mapping functionality. The test demonstrates how specific affine transformation matrices can cause the dst pointer to overflow in the _apply() method.

  • Adds a new CrashDemo.cpp example that applies random transformations to expose edge cases
  • Includes a hardcoded crash case matrix that reliably triggers the buffer overflow
  • Integrates the new example into the meson build system

Reviewed Changes

Copilot reviewed 2 out of 4 changed files in this pull request and generated 2 comments.

File Description
examples/meson.build Adds CrashDemo.cpp to the build configuration
examples/CrashDemo.cpp New stress test that applies random transformations and includes a specific crash case

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +56 to +61
m00 = 0.572866f;
m01 = -4.431353f;
m02 = 336.605835f;
m10 = 5.198910f;
m11 = -0.386219f;
m12 = 30.710693f;
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hardcoded crash case matrix overrides the randomly generated matrix values, making the random generation code (lines 31-45) effectively dead code. Consider adding a flag or parameter to toggle between random and crash case matrices, or separate these into different test modes.

Copilot uses AI. Check for mistakes.

// translate/rotate/scale/shear
float tx = frand(-(float)cw * 1.5f, (float)cw * 1.5f);
float ty = frand(-(float)ch * 1.5f, (float)ch * 1.5f);
float angle = frand(0.0f, 360.0f) * 3.1415926535f / 180.0f;
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic number 3.1415926535f should be replaced with a named constant like M_PI or std::numbers::pi for better maintainability.

Copilot uses AI. Check for mistakes.

@hermet
Copy link
Member

hermet commented Oct 13, 2025

@WangSimiao2000 Thanks for your contribution, It would be nicer if you send a patch to thorvg/test/testSwEngine.cpp

@WangSimiao2000
Copy link
Contributor Author

@hermet
create a new PR:
#3880

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

example Sample Code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载