Ultimaker / CuraEngine

Powerful, fast and robust engine for converting 3D models into g-code instructions for 3D printers. It is part of the larger open source project Cura.
https://ultimaker.com/en/products/cura-software
GNU Affero General Public License v3.0
1.67k stars 880 forks source link

Incorrect printf format string in InfillTest causes test failure on 32-bit architectures #1897

Closed onitake closed 1 year ago

onitake commented 1 year ago

Application Version

5.0.0 until current HEAD ( ef46801bffb289cdcc3ec58b6dfff78b2889644d )

Platform

Linux on i686 (or any 32-bit architecture)

Qt

N/A

PyQt

N/A

Display Driver

N/A

Steps to Reproduce

  1. Compile CuraEngine for a CPU architecture with a 32-bit size_t
  2. Run unit test InfillTest

Actual Results

...
5: 
5: [ FATAL ] /usr/include/gtest/internal/gtest-param-util.h:585:: Condition IsValidParamName(param_name) failed. Parameterized test name 'InfillTestParameters_P2_Z0_C0_L350__-4294967296' is invalid, in ./tests/InfillTest.cpp line 241
5: 
...
96% tests passed, 1 tests failed out of 26

Total Test time (real) =  10.85 sec

The following tests FAILED:
      5 - InfillTest (Subprocess aborted)
Errors while running CTest
make[1]: *** [Makefile:94: test] Error 8

Expected results

The unit test succeeds.

Additional Information

The bug lies in the a printf format string, where %lld is incorrectly used to format a size_t argument. InfillTest runs with very high numbers for this argument which will cause a rollover on 32 architectures if they're interpreted as signed, but size_t is unsigned.

To fix the issue, the correct format string for size_t should be used: %zu Alternatively, changing %lld to %llu will also work in most cases.

This occurred during automatic unit testing of CuraEngine 5.0.0 in Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1040252 But the bug is still present in current HEAD: https://github.com/Ultimaker/CuraEngine/blob/main/tests/InfillTest.cpp#L103