Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.
C++ 3d3d-sculptingcppdear-imguidigital-sculptingfbxgame-developmentgaussian-splattinggltfimage-to-3dmcpopenglopenusdsculptingtext-to-3dunreal-engine
Security: quote video output paths for ffmpeg's command line (timelapse, proof mode, --record); a crafted file name could run a command. Test passes hostile names through the shell.
islandmed34b015f610ad
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c7466146..c062d7b2 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -21,6 +21,9 @@ All notable changes to SculptForge are listed here. The format follows- Insert on the model (#34): the drag's direction also turns the inserted shape about the surface normal.### Fixed+- Security: the timelapse, proof-mode and --record video exports passed the file name to ffmpeg's command line in+ double quotes, so a crafted name (for example a project called `x$(...)`) could run a command. Names are now+ quoted so nothing in them is interpreted (and refused on Windows when they contain shell characters).- The brush ring that follows the surface (#25) read the mesh while a predictive stroke's thread was changing it,which could change where that stroke's dabs landed; it now shows the flat ring during such strokes.diff --git a/src/app/App.cpp b/src/app/App.cppindex 7547ff0e..eafbf52b 100644--- a/src/app/App.cpp+++ b/src/app/App.cpp@@ -1,6 +1,7 @@// SculptForge - open source digital sculpting// SPDX-License-Identifier: GPL-3.0-or-later#include "app/App.h"+#include "app/ShellQuote.h"#include "app/AsyncStroke.h"#include "app/Calibration.h"#include "app/CrashLog.h"@@ -515,10 +516,14 @@ int App::runRecording() {// virtual camera and downsampled.const int ss = std::max(options_.supersample, 1), ow = w / ss, oh = h / ss;// Frames go straight to ffmpeg as raw RGBA.+ if (shellQuote(options_.recordPath).empty()) {+ SDL_Log("--record: choose a file name without \" %% ! ^ & | < > in it");+ return 1;+ }std::string cmd = "ffmpeg -loglevel error -y -f rawvideo -pix_fmt rgba -s " + std::to_string(ow) + "x" + std::to_string(oh) +" -r " + std::to_string(fps) +- " -i - -c:v libx264 -preset slow -crf 18 -pix_fmt yuv420p -movflags +faststart \"" +- options_.recordPath + "\"";+ " -i - -c:v libx264 -preset slow -crf 18 -pix_fmt yuv420p -movflags +faststart " ++ shellQuote(options_.recordPath);#if defined(_WIN32)FILE* ff = _popen(cmd.c_str(), "wb");#elsediff --git a/src/app/PanelTimeline.cpp b/src/app/PanelTimeline.cppindex a8313339..bbb6b0bc 100644--- a/src/app/PanelTimeline.cpp+++ b/src/app/PanelTimeline.cpp@@ -7,6 +7,7 @@// Right-click a stroke to re-tune its strength. Timelapse renders the history as a turntable video. The data// side is core/Timeline.h; Help > Benchmark (proof mode) is in ProofMode.cpp.#include "app/App.h"+#include "app/ShellQuote.h"#include "app/Theme.h"#include "app/Ui.h"@@ -200,9 +201,14 @@ void App::startTimelapse(const std::string& path, int width, int height, float sjob->camera.distance *= 0.72f; // frame() leaves room for any view direction; a turntable can come closerjob->camera.aspect = float(job->width) / float(std::max(job->height, 1));job->yaw0 = camera_.yaw;+ const std::string quoted = shellQuote(path); // (never a shell-active file name)+ if (quoted.empty()) {+ status_ = s.message = "Timelapse: choose a file name without \" % ! ^ & | < > in it";+ return;+ }const std::string cmd = "ffmpeg -loglevel error -y -f rawvideo -pix_fmt rgba -s " + std::to_string(job->width) + "x" +std::to_string(job->height) + " -r " + std::to_string(job->fps) +- " -i - -c:v libx264 -preset medium -crf 18 -pix_fmt yuv420p -movflags +faststart \"" + path + "\"";+ " -i - -c:v libx264 -preset medium -crf 18 -pix_fmt yuv420p -movflags +faststart " + quoted;#if defined(_WIN32)job->ffmpeg = _popen(cmd.c_str(), "wb");#elsediff --git a/src/app/ProofMode.cpp b/src/app/ProofMode.cppindex 5775a9f9..94c0a0d5 100644--- a/src/app/ProofMode.cpp+++ b/src/app/ProofMode.cpp@@ -15,6 +15,7 @@#include "app/ProofMode.h"#include "app/App.h"+#include "app/ShellQuote.h"#include "app/Theme.h"#include "core/Benchmark.h"@@ -219,10 +220,12 @@ public:bool start(const std::string& path, int w, int h) {w_ = w, h_ = h;// Bottom-up rows from glReadPixels: flipped; scaled to at most 1920 wide to keep the encoder light.+ const std::string quoted = shellQuote(path); // (never a shell-active file name)+ if (quoted.empty()) return false;const std::string cmd = "ffmpeg -loglevel error -y -f rawvideo -pix_fmt rgba -s " + std::to_string(w) + "x" +std::to_string(h) + " -r " + std::to_string(kVideoFps) +" -i - -vf \"vflip,scale='min(1920,iw)':-2\" -c:v libx264 -preset veryfast -crf 20 "- "-pix_fmt yuv420p -movflags +faststart \"" + path + "\"";+ "-pix_fmt yuv420p -movflags +faststart " + quoted;#if defined(_WIN32)ff_ = _popen(cmd.c_str(), "wb");#elsediff --git a/src/app/ShellQuote.h b/src/app/ShellQuote.hnew file mode 100644index 00000000..ad4c294e--- /dev/null+++ b/src/app/ShellQuote.h@@ -0,0 +1,25 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+#pragma once++#include <string>++namespace sf {++// One argument for a popen() command line, so a file name can never run commands: POSIX single quotes (a ' inside+// becomes '\''); on Windows double quotes, and an empty result (refuse) for names with " % ! ^ & | < > in them.+inline std::string shellQuote(const std::string& arg) {+#if defined(_WIN32)+ if (arg.find_first_of("\"%!^&|<>\r\n") != std::string::npos) return {};+ return "\"" + arg + "\"";+#else+ std::string out = "'";+ for (char c : arg) {+ if (c == '\'') out += "'\\''";+ else out += c;+ }+ return out + "'";+#endif+}++} // namespace sfdiff --git a/tests/test_shell_quote.cpp b/tests/test_shell_quote.cppnew file mode 100644index 00000000..43c382e9--- /dev/null+++ b/tests/test_shell_quote.cpp@@ -0,0 +1,33 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+// File names reach ffmpeg's command line through shellQuote: nothing in a name may run (timelapse, proof mode,+// --record).+#include "TestHarness.h"++#include "app/ShellQuote.h"++#include <cstdio>+#include <string>++using namespace sf;++TEST(shell_quote_names_never_run) {+#if !defined(_WIN32)+ const std::string names[] = {"plain.mp4", "with space.mp4", "it's.mp4", "a$(touch x).mp4", "b`id`.mp4",+ "c\"d\".mp4", "e;rm -rf nothing.mp4", "f$HOME\\n.mp4", "'''.mp4"};+ for (const std::string& n : names) {+ FILE* p = popen(("printf %s " + shellQuote(n)).c_str(), "r");+ CHECK(p != nullptr);+ std::string out;+ char buf[256];+ size_t got;+ while ((got = std::fread(buf, 1, sizeof buf, p)) > 0) out.append(buf, got);+ pclose(p);+ CHECK(out == n); // the shell gave the name back unchanged: nothing expanded or ran+ }+#else+ CHECK(shellQuote("a\"b.mp4").empty());+ CHECK(shellQuote("50%.mp4").empty());+ CHECK(shellQuote("ok name.mp4") == "\"ok name.mp4\"");+#endif+}