Skip to content
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

[Fuzz] Add Fuzz testing for RegistryPreview #37607

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Revert "fix linelower error and modify filenametext to registryContent"
This reverts commit e8269b8.
  • Loading branch information
chenmy77 committed Mar 3, 2025
commit 0438b203cad3b9873809621ddeaaa43be290aecf
20 changes: 9 additions & 11 deletions PowerToys.sln
Original file line number Diff line number Diff line change
@@ -646,8 +646,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hosts.FuzzTests", "src\modu
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hosts.UITests", "src\modules\Hosts\Hosts.UITests\Hosts.UITests.csproj", "{4E0AE3A4-2EE0-44D7-A2D0-8769977254A0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RegistryPreview.FuzzTests", "src\modules\registrypreview\RegistryPreview.FuzzTests\RegistryPreview.FuzzTests.csproj", "{F99690AC-D81C-4371-81F2-E2E1A62A28F1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM64 = Debug|ARM64
@@ -2296,14 +2294,14 @@ Global
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A0}.Release|ARM64.Build.0 = Release|ARM64
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A0}.Release|x64.ActiveCfg = Release|x64
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A0}.Release|x64.Build.0 = Release|x64
{F99690AC-D81C-4371-81F2-E2E1A62A28F1}.Debug|ARM64.ActiveCfg = Debug|ARM64
{F99690AC-D81C-4371-81F2-E2E1A62A28F1}.Debug|ARM64.Build.0 = Debug|ARM64
{F99690AC-D81C-4371-81F2-E2E1A62A28F1}.Debug|x64.ActiveCfg = Debug|x64
{F99690AC-D81C-4371-81F2-E2E1A62A28F1}.Debug|x64.Build.0 = Debug|x64
{F99690AC-D81C-4371-81F2-E2E1A62A28F1}.Release|ARM64.ActiveCfg = Release|ARM64
{F99690AC-D81C-4371-81F2-E2E1A62A28F1}.Release|ARM64.Build.0 = Release|ARM64
{F99690AC-D81C-4371-81F2-E2E1A62A28F1}.Release|x64.ActiveCfg = Release|x64
{F99690AC-D81C-4371-81F2-E2E1A62A28F1}.Release|x64.Build.0 = Release|x64
{50A9F3DE-CF0B-4CF0-AFDE-3A3E245D7734}.Debug|ARM64.ActiveCfg = Debug|ARM64
{50A9F3DE-CF0B-4CF0-AFDE-3A3E245D7734}.Debug|ARM64.Build.0 = Debug|ARM64
{50A9F3DE-CF0B-4CF0-AFDE-3A3E245D7734}.Debug|x64.ActiveCfg = Debug|x64
{50A9F3DE-CF0B-4CF0-AFDE-3A3E245D7734}.Debug|x64.Build.0 = Debug|x64
{50A9F3DE-CF0B-4CF0-AFDE-3A3E245D7734}.Release|ARM64.ActiveCfg = Release|ARM64
{50A9F3DE-CF0B-4CF0-AFDE-3A3E245D7734}.Release|ARM64.Build.0 = Release|ARM64
{50A9F3DE-CF0B-4CF0-AFDE-3A3E245D7734}.Release|x64.ActiveCfg = Release|x64
{50A9F3DE-CF0B-4CF0-AFDE-3A3E245D7734}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -2544,7 +2542,7 @@ Global
{4382A954-179A-4078-92AF-715187DFFF50} = {38BDB927-829B-4C65-9CD9-93FB05D66D65}
{EBED240C-8702-452D-B764-6DB9DA9179AF} = {F05E590D-AD46-42BE-9C25-6A63ADD2E3EA}
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A0} = {F05E590D-AD46-42BE-9C25-6A63ADD2E3EA}
{F99690AC-D81C-4371-81F2-E2E1A62A28F1} = {929C1324-22E8-4412-A9A8-80E85F3985A5}
{50A9F3DE-CF0B-4CF0-AFDE-3A3E245D7734} = {929C1324-22E8-4412-A9A8-80E85F3985A5}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0}
1 change: 0 additions & 1 deletion deps/cxxopts
Submodule cxxopts deleted from 12e496
2 changes: 1 addition & 1 deletion deps/cziplib
2 changes: 1 addition & 1 deletion deps/spdlog
Submodule spdlog updated 74 files
+1 −1 .clang-tidy
+47 −4 CMakeLists.txt
+6 −2 README.md
+27 −7 appveyor.yml
+18 −1 bench/CMakeLists.txt
+5 −0 bench/async_bench.cpp
+5 −0 bench/bench.cpp
+5 −5 bench/formatter-bench.cpp
+14 −0 cmake/spdlogCPack.cmake
+1 −0 cmake/utils.cmake
+2 −2 example/example.cpp
+1 −0 include/spdlog/cfg/helpers-inl.h
+12 −10 include/spdlog/common-inl.h
+40 −7 include/spdlog/common.h
+2 −1 include/spdlog/details/backtracer.h
+17 −2 include/spdlog/details/file_helper-inl.h
+3 −1 include/spdlog/details/log_msg_buffer-inl.h
+6 −0 include/spdlog/details/mpmc_blocking_q.h
+67 −22 include/spdlog/details/os-inl.h
+9 −2 include/spdlog/details/os.h
+1 −1 include/spdlog/details/registry.h
+2 −1 include/spdlog/details/synchronous_factory.h
+1 −1 include/spdlog/details/tcp_client-windows.h
+2 −2 include/spdlog/details/tcp_client.h
+6 −1 include/spdlog/details/thread_pool-inl.h
+1 −0 include/spdlog/details/thread_pool.h
+37 −42 include/spdlog/fmt/bundled/chrono.h
+47 −10 include/spdlog/fmt/bundled/color.h
+59 −23 include/spdlog/fmt/bundled/compile.h
+344 −104 include/spdlog/fmt/bundled/core.h
+1,621 −273 include/spdlog/fmt/bundled/format-inl.h
+694 −463 include/spdlog/fmt/bundled/format.h
+15 −29 include/spdlog/fmt/bundled/locale.h
+67 −37 include/spdlog/fmt/bundled/os.h
+19 −9 include/spdlog/fmt/bundled/ostream.h
+2 −2 include/spdlog/fmt/bundled/printf.h
+16 −6 include/spdlog/fmt/bundled/ranges.h
+2 −1 include/spdlog/fmt/fmt.h
+24 −23 include/spdlog/logger.h
+26 −4 include/spdlog/pattern_formatter-inl.h
+2 −2 include/spdlog/pattern_formatter.h
+2 −0 include/spdlog/sinks/ansicolor_sink-inl.h
+1 −1 include/spdlog/sinks/base_sink.h
+2 −1 include/spdlog/sinks/basic_file_sink.h
+34 −0 include/spdlog/sinks/daily_file_sink.h
+1 −1 include/spdlog/sinks/dup_filter_sink.h
+194 −0 include/spdlog/sinks/hourly_file_sink.h
+2 −1 include/spdlog/sinks/stdout_color_sinks-inl.h
+19 −3 include/spdlog/sinks/stdout_sinks-inl.h
+15 −5 include/spdlog/sinks/win_eventlog_sink.h
+59 −54 include/spdlog/sinks/wincolor_sink-inl.h
+10 −19 include/spdlog/sinks/wincolor_sink.h
+17 −17 include/spdlog/spdlog.h
+51 −1 include/spdlog/tweakme.h
+1 −1 include/spdlog/version.h
+8 −8 scripts/extract_version.py
+2 −1 src/async.cpp
+2 −1 src/cfg.cpp
+1 −0 src/color_sinks.cpp
+2 −1 src/file_sinks.cpp
+61 −21 src/fmt.cpp
+2 −1 src/spdlog.cpp
+2 −1 src/stdout_sinks.cpp
+8 −6 tests/test_async.cpp
+35 −41 tests/test_create_dir.cpp
+32 −18 tests/test_daily_logger.cpp
+11 −8 tests/test_errors.cpp
+3 −3 tests/test_eventlog.cpp
+26 −28 tests/test_file_helper.cpp
+16 −14 tests/test_file_logging.cpp
+7 −5 tests/test_macros.cpp
+1 −1 tests/test_pattern_formatter.cpp
+1 −1 tests/test_registry.cpp
+5 −3 tests/utils.cpp
Original file line number Diff line number Diff line change
@@ -24,9 +24,9 @@ public static void FuzzCheckKeyLineForBrackets(ReadOnlySpan<byte> input)
string registryLine;

// Simulate registry file content as filenameText
var registryContent = GenerateRegistryHeader(input);
var filenameText = GenerateRegistryHeader(input);
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on the comments, the result represents registry file content, so the name filenameText might be confusing. Would registryContent be a better choice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I also think so,registryContent would be a better choice than filenameText. I will modify it.


string[] registryLines = registryContent.Split("\r");
string[] registryLines = filenameText.Split("\r");

if (registryLines.Length <= 1)
{
@@ -75,9 +75,10 @@ public static void FuzzStripFirstAndLast(ReadOnlySpan<byte> input)
{
string registryLine;

var regisrtyContent = GenerateRegistryHeader(input);
var filenameText = GenerateRegistryHeader(input);

string[] registryLines = regisrtyContent.Split("\r");
filenameText = filenameText.Replace("\r\n", "\r");
string[] registryLines = filenameText.Split("\r");

if (registryLines.Length <= 1)
{
@@ -177,14 +178,16 @@ public static string GenerateRegistryHeader(ReadOnlySpan<byte> input)
string header = new Random().Next(2) == 0 ? REGISTRYHEADER4 : REGISTRYHEADER5;

string inputText = System.Text.Encoding.UTF8.GetString(input);
string registryContent = header + "\r" + inputText;
string filenameText = header + "\r\n" + inputText;

return registryContent;
return filenameText.Replace("\r\n", "\r");
}

private static bool IsValidRegistryHeader(string line)
{
// Convert the line to lowercase once for comparison
var lineLower = line.ToLowerInvariant();

switch (line)
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed that you're using switch (line), which relies on the original line, but you convert lineLower to lowercase for comparison. Which one do you actually intend to use?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I intend to use the line, and the lineLower needs to be removed.

{
case REGISTRYHEADER4:
Loading
Oops, something went wrong.