Skip to content

Commit cb9b32c

Browse files
committed
fix(sr): harden plugin lifecycle and download pipeline
1 parent 131e085 commit cb9b32c

17 files changed

Lines changed: 258 additions & 83 deletions

‎CMakeLists.txt‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,14 @@ set_target_properties(QuickView PROPERTIES LINK_FLAGS "${QUICKVIEW_LINK_FLAGS}")
150150
# Include paths
151151
target_include_directories(QuickView PRIVATE QuickView third_party/yyjson third_party/unrar-mini third_party/webview2)
152152

153-
# Precompiled Headers (PCH) - CXX only to avoid conflict with C source (yyjson.c)
154-
target_precompile_headers(QuickView PRIVATE $<$<COMPILE_LANGUAGE:CXX>:pch.h>)
155-
156153
# Disable PCH for specific files (as defined in .vcxproj)
157154
set_source_files_properties(QuickView/WuffsImpl.cpp PROPERTIES SKIP_PRECOMPILED_HEADERS ON)
158155
set_source_files_properties(QuickView/ImageLoaderSimd.cpp PROPERTIES SKIP_PRECOMPILED_HEADERS ON)
159156
set_source_files_properties(third_party/yyjson/yyjson.c PROPERTIES SKIP_PRECOMPILED_HEADERS ON)
160157

158+
# Precompiled Headers (PCH) - CXX only to avoid conflict with C source (yyjson.c)
159+
target_precompile_headers(QuickView PRIVATE $<$<COMPILE_LANGUAGE:CXX>:pch.h>)
160+
161161
# ============================================================================
162162
# Compiler & Linker Flags (Clang-CL Matrix)
163163
# ============================================================================
@@ -207,7 +207,7 @@ if(MSVC OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
207207

208208
if(ENABLE_LTO)
209209
message(STATUS "Build Matrix: Enabling Full LTO (Release-LTO Pure Maximum Speed)")
210-
# Pure peak performance flags (Pure /O2, no /Oscompromise)
210+
# Pure peak performance flags for Hot-Path (Pure /O2, no compromise)
211211
target_compile_options(QuickView PRIVATE
212212
/O2 /Gw /Gy /Zc:inline /GR- /fp:fast /GS- /EHs-c- /Z7
213213
/clang:-flto=full

‎QuickView/AppStrings.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
#include <windows.h> // For GetUserDefaultUILanguage
44
#include "EditState.h"
55

6+
#if defined(__clang__)
7+
#pragma clang diagnostic push
8+
#pragma clang diagnostic ignored "-Wignored-attributes"
9+
#pragma clang attribute push([[clang::minsize]], apply_to = function)
10+
#endif
11+
612
extern AppConfig g_config;
713

814
namespace AppStrings {
@@ -7364,3 +7370,7 @@ const wchar_t* Settings_Button_Download = L"Download";
73647370

73657371
}
73667372

7373+
#if defined(__clang__)
7374+
#pragma clang attribute pop
7375+
#pragma clang diagnostic pop
7376+
#endif

‎QuickView/ArchiveVFS.cpp‎

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,23 @@ namespace QuickView {
5454
void (*progressCb)(float progress, void* userData),
5555
void* userData
5656
) {
57-
char logBuf[512];
58-
sprintf_s(logBuf, "[QVX-Extract] ExtractZipToDirectory: opening '%ls' -> '%ls'\n", zipPath.c_str(), destDir.c_str());
59-
OutputDebugStringA(logBuf);
60-
6157
ZipArchive zip(zipPath);
6258
if (!zip.IsValid()) {
63-
sprintf_s(logBuf, "[QVX-Extract] Failed: zip.IsValid() is false for '%ls'\n", zipPath.c_str());
64-
OutputDebugStringA(logBuf);
6559
return false;
6660
}
6761

62+
constexpr size_t kMaxEntries = 4096;
63+
constexpr uint64_t kMaxEntryBytes = 512ull * 1024 * 1024;
64+
constexpr uint64_t kMaxTotalBytes = 1024ull * 1024 * 1024;
6865
size_t totalEntries = zip.GetEntryCount();
69-
sprintf_s(logBuf, "[QVX-Extract] Zip has %zu entries\n", totalEntries);
70-
OutputDebugStringA(logBuf);
71-
66+
if (totalEntries > kMaxEntries) return false;
7267
if (totalEntries == 0) return true;
7368

7469
EnsureParentDirectory(destDir + L"\\dummy.tmp");
7570

7671
::std::vector<uint8_t> buffer;
7772

73+
uint64_t totalUncompressed = 0;
7874
for (size_t i = 0; i < totalEntries; ++i) {
7975
::std::wstring relName = zip.GetEntryName(i);
8076
if (relName.empty()) continue;
@@ -84,7 +80,8 @@ namespace QuickView {
8480
}
8581

8682
// Security: Prevent Directory Traversal
87-
if (relName.find(L"..\\") != ::std::wstring::npos || relName.find(L"\\..") != ::std::wstring::npos) {
83+
if (relName.front() == L'\\' || relName.find(L':') != ::std::wstring::npos ||
84+
relName.find(L"..\\") != ::std::wstring::npos || relName == L".." || relName.find(L"\\..") != ::std::wstring::npos) {
8885
continue;
8986
}
9087

@@ -96,17 +93,15 @@ namespace QuickView {
9693
EnsureParentDirectory(outPath);
9794

9895
const ArchiveEntry& entry = zip.GetEntry(i);
99-
sprintf_s(logBuf, "[QVX-Extract] Entry [%zu]: '%ls', uncompSize=%u, method=%u\n", i, relName.c_str(), entry.uncompSize, entry.method);
100-
OutputDebugStringA(logBuf);
96+
if (entry.uncompSize > kMaxEntryBytes || totalUncompressed > kMaxTotalBytes - entry.uncompSize) return false;
97+
totalUncompressed += entry.uncompSize;
10198

10299
if (buffer.size() < entry.uncompSize) {
103100
buffer.resize(entry.uncompSize);
104101
}
105102

106103
size_t extractedSize = zip.ExtractEntry(i, buffer.data(), buffer.size());
107104
if (extractedSize != entry.uncompSize) {
108-
sprintf_s(logBuf, "[QVX-Extract] ExtractEntry failed for '%ls' (got %zu, expected %u)\n", relName.c_str(), extractedSize, entry.uncompSize);
109-
OutputDebugStringA(logBuf);
110105
return false;
111106
}
112107

@@ -116,8 +111,6 @@ namespace QuickView {
116111
DeleteFileW(outPath.c_str());
117112
hFile = CreateFileW(outPath.c_str(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
118113
if (hFile == INVALID_HANDLE_VALUE) {
119-
sprintf_s(logBuf, "[QVX-Extract] CreateFileW failed for '%ls' (err=%lu)\n", outPath.c_str(), GetLastError());
120-
OutputDebugStringA(logBuf);
121114
return false;
122115
}
123116
}
@@ -130,8 +123,6 @@ namespace QuickView {
130123
CloseHandle(hFile);
131124

132125
if (!writeOk || written != entry.uncompSize) {
133-
sprintf_s(logBuf, "[QVX-Extract] WriteFile failed for '%ls' (written=%lu, expected=%u, err=%lu)\n", outPath.c_str(), written, entry.uncompSize, GetLastError());
134-
OutputDebugStringA(logBuf);
135126
DeleteFileW(outPath.c_str());
136127
return false;
137128
}
@@ -142,8 +133,6 @@ namespace QuickView {
142133
}
143134
}
144135

145-
sprintf_s(logBuf, "[QVX-Extract] ExtractZipToDirectory completed successfully for '%ls'\n", zipPath.c_str());
146-
OutputDebugStringA(logBuf);
147136
return true;
148137
}
149138

‎QuickView/ContextMenu.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
#include "UndoManager.h"
77
#include "Plugin/PluginHost.h"
88

9+
#if defined(__clang__)
10+
#pragma clang diagnostic push
11+
#pragma clang diagnostic ignored "-Wignored-attributes"
12+
#pragma clang attribute push([[clang::minsize]], apply_to = function)
13+
#endif
14+
915
extern AppConfig g_config;
1016
extern RuntimeConfig g_runtime;
1117

@@ -242,3 +248,8 @@ void ShowGalleryContextMenu(HWND hwnd, POINT pt) {
242248

243249
GeekContextMenu::ShowMenu(hwnd, pt.x, pt.y, {}, std::move(items));
244250
}
251+
252+
#if defined(__clang__)
253+
#pragma clang attribute pop
254+
#pragma clang diagnostic pop
255+
#endif

‎QuickView/DialogController.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
#include "SettingsOverlay.h"
1111
#include "GeekWidgets.h"
1212

13+
#if defined(__clang__)
14+
#pragma clang diagnostic push
15+
#pragma clang diagnostic ignored "-Wignored-attributes"
16+
#pragma clang attribute push([[clang::minsize]], apply_to = function)
17+
#endif
18+
1319
extern float g_uiScale;
1420
extern AppConfig g_config;
1521
extern HIMC g_defaultIMC;
@@ -811,3 +817,8 @@ DialogResult DialogController::ShowChoiceDialog(
811817
inOutSelectedIndex = m_context.Dialog.SelectedChoiceIndex;
812818
return m_context.Dialog.FinalResult;
813819
}
820+
821+
#if defined(__clang__)
822+
#pragma clang attribute pop
823+
#pragma clang diagnostic pop
824+
#endif

‎QuickView/DisplayColorInfo.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ static constexpr const char* CURRENT_MODULE = "DisplayColorInfo";
1818
#include <wrl/client.h>
1919
#include <wrl/wrappers/corewrappers.h>
2020

21+
#if defined(__clang__)
22+
#pragma clang diagnostic push
23+
#pragma clang diagnostic ignored "-Wignored-attributes"
24+
#pragma clang attribute push([[clang::minsize]], apply_to = function)
25+
#endif
26+
2127
#pragma comment(lib, "runtimeobject.lib")
2228
#pragma comment(lib, "mscms.lib")
2329

@@ -481,3 +487,8 @@ const wchar_t* ToString(ColorPrimaries value) {
481487
}
482488

483489
} // namespace QuickView
490+
491+
#if defined(__clang__)
492+
#pragma clang attribute pop
493+
#pragma clang diagnostic pop
494+
#endif

‎QuickView/ExportPanel.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
#include "ImageEngine.h"
2121
#include <thread>
2222

23+
#if defined(__clang__)
24+
#pragma clang diagnostic push
25+
#pragma clang diagnostic ignored "-Wignored-attributes"
26+
#pragma clang attribute push([[clang::minsize]], apply_to = function)
27+
#endif
28+
2329
extern std::unique_ptr<ImageEngine> g_imageEngine;
2430

2531
extern float g_uiScale;
@@ -1754,3 +1760,8 @@ void ExportPanel::DrawQualitySlider(ID2D1DeviceContext* dc, const D2D1_RECT_F& r
17541760
}
17551761

17561762
} // namespace QuickView
1763+
1764+
#if defined(__clang__)
1765+
#pragma clang attribute pop
1766+
#pragma clang diagnostic pop
1767+
#endif

‎QuickView/GeekContextMenu.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
#include <d2d1_1.h>
1010
#include <cmath>
1111

12+
#if defined(__clang__)
13+
#pragma clang diagnostic push
14+
#pragma clang diagnostic ignored "-Wignored-attributes"
15+
#pragma clang attribute push([[clang::minsize]], apply_to = function)
16+
#endif
17+
1218
extern class CRenderEngine* g_pRenderEngine;
1319

1420
#pragma comment(lib, "d2d1.lib")
@@ -1160,3 +1166,8 @@ void GeekContextMenu::RenderAndUI() {
11601166
}
11611167

11621168
} // namespace QuickView::UI::Menu
1169+
1170+
#if defined(__clang__)
1171+
#pragma clang attribute pop
1172+
#pragma clang diagnostic pop
1173+
#endif

‎QuickView/HelpOverlay.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
#include "EditState.h"
66
#include "GeekIconRenderer.h"
77

8+
#if defined(__clang__)
9+
#pragma clang diagnostic push
10+
#pragma clang diagnostic ignored "-Wignored-attributes"
11+
#pragma clang attribute push([[clang::minsize]], apply_to = function)
12+
#endif
13+
814
extern AppConfig g_config;
915

1016

@@ -454,3 +460,8 @@ void HelpOverlay::OnLButtonDown(float x, float y) {
454460
SetVisible(false); // Close on click outside
455461
}
456462
}
463+
464+
#if defined(__clang__)
465+
#pragma clang attribute pop
466+
#pragma clang diagnostic pop
467+
#endif

0 commit comments

Comments
 (0)