-
-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Undefined Behavior Case #121
Comments
Fixed error in building instructions. Now it points to the correct repository. |
Hi @sammycage 👋 How are you? I just wanted to know if I could provide any extra information to help fix this bug. From my understanding so far, I think the problem is that it was not rejected either by Document::loadFromData or bitmap.valid(). Do you have any opinions or thoughts on the cause of this issue? Best regards, |
I need this file |
Hi @sammycage Here is the file. I should have made it available easier; sorry for that. Best regards, |
This file contains some invalid characters. |
There are no errors on my machine... Am I doing something wrong? sammycage@ubuntu:~/Projects/lunasvg$ mkdir build && cd build sammycage@ubuntu:~/Projects/lunasvg/build$ CXX=clang++-12 CC=clang-12 cmake -DLUNASVG_BUILD_EXAMPLES=ON -DCMAKE_CXX_FLAGS="-g -O0 -fsanitize=undefined,address -fno-sanitize-recover=all" -DCMAKE_C_FLAGS="-g -O0 -fsanitize=undefined,address -fno-sanitize-recover=all" .. -- The CXX compiler identification is Clang 12.0.1 -- The C compiler identification is Clang 12.0.1 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/clang++-12 - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/clang-12 - skipped -- Detecting C compile features -- Detecting C compile features - done -- Configuring done -- Generating done -- Build files have been written to: /home/sammycage/Projects/lunasvg/build sammycage@ubuntu:~/Projects/lunasvg/build$ make -j3 [ 3%] Building CXX object CMakeFiles/lunasvg.dir/source/lunasvg.cpp.o [ 9%] Building CXX object CMakeFiles/lunasvg.dir/source/property.cpp.o [ 9%] Building CXX object CMakeFiles/lunasvg.dir/source/element.cpp.o [ 12%] Building CXX object CMakeFiles/lunasvg.dir/source/parser.cpp.o [ 15%] Building CXX object CMakeFiles/lunasvg.dir/source/layoutcontext.cpp.o [ 18%] Building CXX object CMakeFiles/lunasvg.dir/source/canvas.cpp.o [ 21%] Building CXX object CMakeFiles/lunasvg.dir/source/clippathelement.cpp.o [ 25%] Building CXX object CMakeFiles/lunasvg.dir/source/defselement.cpp.o [ 28%] Building CXX object CMakeFiles/lunasvg.dir/source/gelement.cpp.o [ 31%] Building CXX object CMakeFiles/lunasvg.dir/source/geometryelement.cpp.o [ 34%] Building CXX object CMakeFiles/lunasvg.dir/source/graphicselement.cpp.o [ 37%] Building CXX object CMakeFiles/lunasvg.dir/source/maskelement.cpp.o [ 40%] Building CXX object CMakeFiles/lunasvg.dir/source/markerelement.cpp.o [ 43%] Building CXX object CMakeFiles/lunasvg.dir/source/paintelement.cpp.o [ 46%] Building CXX object CMakeFiles/lunasvg.dir/source/stopelement.cpp.o [ 50%] Building CXX object CMakeFiles/lunasvg.dir/source/styledelement.cpp.o [ 53%] Building CXX object CMakeFiles/lunasvg.dir/source/styleelement.cpp.o [ 56%] Building CXX object CMakeFiles/lunasvg.dir/source/svgelement.cpp.o [ 59%] Building CXX object CMakeFiles/lunasvg.dir/source/symbolelement.cpp.o [ 62%] Building CXX object CMakeFiles/lunasvg.dir/source/useelement.cpp.o [ 65%] Building C object CMakeFiles/lunasvg.dir/3rdparty/plutovg/plutovg.c.o [ 68%] Building C object CMakeFiles/lunasvg.dir/3rdparty/plutovg/plutovg-paint.c.o [ 71%] Building C object CMakeFiles/lunasvg.dir/3rdparty/plutovg/plutovg-geometry.c.o [ 75%] Building C object CMakeFiles/lunasvg.dir/3rdparty/plutovg/plutovg-blend.c.o [ 78%] Building C object CMakeFiles/lunasvg.dir/3rdparty/plutovg/plutovg-rle.c.o [ 81%] Building C object CMakeFiles/lunasvg.dir/3rdparty/plutovg/plutovg-dash.c.o [ 84%] Building C object CMakeFiles/lunasvg.dir/3rdparty/plutovg/plutovg-ft-raster.c.o [ 87%] Building C object CMakeFiles/lunasvg.dir/3rdparty/plutovg/plutovg-ft-stroker.c.o [ 90%] Building C object CMakeFiles/lunasvg.dir/3rdparty/plutovg/plutovg-ft-math.c.o [ 93%] Linking CXX shared library liblunasvg.so [ 93%] Built target lunasvg [ 96%] Building CXX object example/CMakeFiles/svg2png.dir/svg2png.cpp.o [100%] Linking CXX executable svg2png [100%] Built target svg2png sammycage@ubuntu:~/Projects/lunasvg/build$ UBSAN_OPTIONS=halt_on_error=1:print_stacktrace=1 ASAN_OPTIONS=halt_on_error=1 example/svg2png '/home/sammycage/Downloads/e-feMorphology-009.bmfull_rand_base.ts3.e18.s0.sid451.smtbit_opt_uc.svg' Generated PNG file : e-feMorphology-009.bmfull_rand_base.ts3.e18.s0.sid451.smtbit_opt_uc.svg.png sammycage@ubuntu:~/Projects/lunasvg/build$ |
Hi @sammycage, Thanks for checking this issue 😃
To reproduce the bug, in svg2png, it is required to use To do so,
Here you have a patch to modify master as required:
Please note that how the bytes are loaded into To sum up, the steps are as follows:
I apologise for any confusion. Please let me know if I can help with anything else. Best regards, |
Hi @sammycage I minimized the SVG file I originally reported. This new SVG file is valid, shorter, and triggers the same UB error. You can use
Minimized SVG file: example.svg I hope this test case is more helpful in solving the issue. Let me know if I can still improve this report, and thanks for sharing this project. Best regards, |
Could you please try to reproduce this error with gcc? I'm encountering difficulties with clang. |
Hi @sammycage Thanks for your quick response! GCC's sanitiser does not detect the problem, but there is a real issue, as reported by clang: The reported line by clang is: I checked In addition, I checked the raised floating-point exceptions using The Using both compilers, I confirmed that To summarize, the I found two possible ways to fix the UB and still correctly render the SVG. At another callsite of
I tested this change, which applies the same check, and it seems to work:
Alternatively, I tested
Let me know if there is anything else I can do. I can also open a pull request if any of the fixes look good to you. Best regards, |
while(buffer < end)
{
uint32_t result = 0; // .
if(det >= 0)
result = gradient_pixel(gradient, sqrt(det) - b);
*buffer++ = result;
det += delta_det;
delta_det += delta_delta_det;
b += delta_b;
} Just being curious, what are you using this library for? |
@sammycage I appreciate your quick response. I opened a PR for this fix.
We are using it as a benchmark for a fuzzing research project. Thanks for sharing LunaSVG o/ |
Thanks for your findings, this especially #119 |
You're welcome. Thanks for your time as well and for sharing this project! |
Hi 👋
I'd like to report the following test case that triggers UB in lunasvg.
The file can be found here. The harness is a slightly modified version of svg2png. It calls
Document::loadFromData(buffer, size);
instead ofDocument::loadFromFile(filename);
. The test case comes from fuzzing.An important remark I think is that this test case is not rejected by
Document::loadFromData
orbitmap.valid()
.Build settings:
git clone -b test-cases https://github.com/m-carrasco/lunasvg.git
mkdir build && cd build
CXX=clang++-12 CC=clang-12 cmake -DLUNASVG_BUILD_EXAMPLES=ON -DCMAKE_CXX_FLAGS="-g -O0 -fsanitize=undefined,address -fno-sanitize-recover=all" -DCMAKE_C_FLAGS="-g -O0 -fsanitize=undefined,address -fno-sanitize-recover=all" ../lunasvg/
How to execute:
UBSAN_OPTIONS=halt_on_error=1:print_stacktrace=1 ASAN_OPTIONS=halt_on_error=1 build/example/svg2png lunasvg/test-cases/e-feMorphology-009.bmfull_rand_base.ts3.e18.s0.sid451.smtbit_opt_uc.svg
Error log:
Thanks a lot for sharing this project!
Best regards,
Manuel
The text was updated successfully, but these errors were encountered: