Skip to content

Commit 79cf80e

Browse files
claudiamurialdoBeta Bot
authored andcommitted
Cherry pick branch 'genexuslabs:fix/code-ql-redos-log-forging' into beta
1 parent f92939f commit 79cf80e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

dotnet/src/dotnetframework/GxCompress/GXCompressor.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,14 @@ private static void DecompressZip(FileInfo file, string outputPath)
603603
foreach (var entry in archive.Entries)
604604
{
605605
string fullPath = Path.Combine(outputPath, entry.FullName);
606+
string destFileName = Path.GetFullPath(fullPath);
607+
string fullDestDirPath = Path.GetFullPath(outputPath + Path.DirectorySeparatorChar);
608+
if (!destFileName.StartsWith(fullDestDirPath))
609+
{
610+
throw new InvalidOperationException("Entry is outside the target dir: " + destFileName);
611+
}
612+
613+
606614
if (string.IsNullOrEmpty(entry.Name))
607615
{
608616
Directory.CreateDirectory(fullPath);
@@ -742,6 +750,14 @@ private static void DecompressJar(FileInfo file, string outputPath)
742750
foreach (var entry in archive.Entries)
743751
{
744752
string destinationPath = Path.Combine(outputPath, entry.FullName);
753+
string destFileName = Path.GetFullPath(destinationPath);
754+
string fullDestDirPath = Path.GetFullPath(outputPath + Path.DirectorySeparatorChar);
755+
if (!destFileName.StartsWith(fullDestDirPath))
756+
{
757+
throw new InvalidOperationException("Entry is outside the target dir: " + destFileName);
758+
}
759+
760+
745761
if (string.IsNullOrEmpty(entry.Name))
746762
{
747763
Directory.CreateDirectory(destinationPath);

0 commit comments

Comments
 (0)