• R/O
  • SSH

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javaandroidc++linuxc#objective-c誰得cocoaqtpythonrubywindowsphpgameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwitterdombtronvb.nettestarduinodirectxpreviewerゲームエンジン

This is a fork of Zandronum for TSPG.


コミットメタ情報

リビジョン1e921845d52651f84bcd6acc708d8df8121c7991 (tree)
日時2021-01-25 05:53:03
作者Adam Kaminski <kaminskiadam9@gmai...>
コミッターAdam Kaminski

ログメッセージ

Refined the duplicate lump check inside ZIP/PK3 files. Now, a fatal error only occurs if any duplicate lumps that are found need to be authenticated by the server. Otherwise, a console error message will be printed during startup and the file will be allowed to load.

変更サマリ

差分

diff -r f53521bf7613 -r 1e921845d526 src/network.cpp
--- a/src/network.cpp Fri Jan 22 00:11:36 2021 +0000
+++ b/src/network.cpp Sun Jan 24 20:53:03 2021 +0000
@@ -359,6 +359,20 @@
359359
360360 for ( unsigned int i = 0; i < lumpsToAuthenticate.size(); i++ )
361361 {
362+ // [AK] Check if we're authenticating any duplicate lumps on the server.
363+ if ( NETWORK_GetState() == NETSTATE_SERVER )
364+ {
365+ for ( unsigned int j = 0; j < DuplicateLumps.Size(); j++ )
366+ {
367+ // [AK] If there's a match, throw a fatal error instead.
368+ if ( stricmp( DuplicateLumps[j], lumpsToAuthenticate[i].c_str() ) == 0 )
369+ {
370+ I_Error( "Attempt to authenticate duplicate protected lump '%s'.\n", lumpsToAuthenticate[i].c_str() );
371+ return;
372+ }
373+ }
374+ }
375+
362376 switch ( lumpsToAuthenticateMode[i] ){
363377 case LAST_LUMP:
364378 int lump;
@@ -986,6 +1000,24 @@
9861000 {
9871001 if ( LumpNumber == -1 )
9881002 return;
1003+
1004+ // [AK] Check if we're trying to authenticate a duplicate lump on the server.
1005+ if ( NETWORK_GetState() == NETSTATE_SERVER )
1006+ {
1007+ const char *lumpName = Wads.GetLumpFullName( LumpNumber );
1008+ for ( unsigned int i = 0; i < DuplicateLumps.Size(); i++ )
1009+ {
1010+ // [AK] If there's a match, throw a fatal error instead.
1011+ if ( DuplicateLumps[i].CompareNoCase( lumpName ) == 0 )
1012+ {
1013+ FString fullPath = Wads.GetLumpFullPath( LumpNumber );
1014+ const char *fileName = fullPath.Left( fullPath.Len() - strlen( lumpName ) - 1 );
1015+
1016+ I_Error( "Attempt to authenticate duplicate lump '%s' found in '%s'.\n", lumpName, fileName );
1017+ return;
1018+ }
1019+ }
1020+ }
9891021
9901022 g_LumpNumsToAuthenticate.Push ( LumpNumber );
9911023 }
diff -r f53521bf7613 -r 1e921845d526 src/resourcefiles/file_7z.cpp
--- a/src/resourcefiles/file_7z.cpp Fri Jan 22 00:11:36 2021 +0000
+++ b/src/resourcefiles/file_7z.cpp Sun Jan 24 20:53:03 2021 +0000
@@ -263,7 +263,6 @@
263263
264264 Lumps = new F7ZLump[NumLumps];
265265
266- FString oldName; // [AK] Store the name of the last lump we scanned.
267266 F7ZLump *lump_p = Lumps;
268267 TArray<UInt16> nameUTF16;
269268 TArray<char> nameASCII;
@@ -298,22 +297,12 @@
298297 FString name = &nameASCII[0];
299298 name.ToLower();
300299
301- // [AK] Check for any duplicate lumps in the file. If we find any, then throw an error. We
302- // shouldn't be loading any malformed 7z files, as this can lead to authentication issues.
303- if ((oldName.IsNotEmpty()) && (oldName.CompareNoCase(name) == 0))
304- {
305- I_Error("Couldn't load file %s: duplicate lump '%s' detected.\n", Filename, name.GetChars());
306- return false;
307- }
308-
309300 lump_p->LumpNameSetup(name);
310301 lump_p->LumpSize = int(file->Size);
311302 lump_p->Owner = this;
312303 lump_p->Flags = LUMPF_ZIPFILE;
313304 lump_p->Position = i;
314305 lump_p->CheckEmbedded();
315-
316- oldName = name; // [AK]
317306 lump_p++;
318307 }
319308 // Resize the lump record array to its actual size
diff -r f53521bf7613 -r 1e921845d526 src/resourcefiles/file_zip.cpp
--- a/src/resourcefiles/file_zip.cpp Fri Jan 22 00:11:36 2021 +0000
+++ b/src/resourcefiles/file_zip.cpp Sun Jan 24 20:53:03 2021 +0000
@@ -205,7 +205,10 @@
205205 Reader->Seek(LittleLong(info.DirectoryOffset), SEEK_SET);
206206 Reader->Read(directory, dirsize);
207207
208- FString oldName; // [AK] Store the name of the last lump we scanned.
208+ // [AK] Store the names of all the lumps in the current directory.
209+ TArray<FString> oldNames;
210+ FString currentDirectory;
211+
209212 char *dirptr = (char*)directory;
210213 FZipLump *lump_p = Lumps;
211214 for (DWORD i = 0; i < NumLumps; i++)
@@ -232,14 +235,6 @@
232235 skipped++;
233236 continue;
234237 }
235-
236- // [AK] Check for any duplicate lumps in the file. If we find any, then throw an error. We
237- // shouldn't be loading any malformed zip files, as this can lead to authentication issues.
238- if ((oldName.IsNotEmpty()) && (oldName.CompareNoCase(name) == 0))
239- {
240- I_Error("Couldn't load file %s: duplicate lump '%s' detected.\n", Filename, name.GetChars());
241- return false;
242- }
243238
244239 // Ignore unknown compression formats
245240 zip_fh->Method = LittleShort(zip_fh->Method);
@@ -283,7 +278,60 @@
283278 memset(lump_p->Name, 0, sizeof(lump_p->Name));
284279 }
285280
286- oldName = name; // [AK]
281+ // [AK] Get the full name of the directory that the lump is located in.
282+ const char *directory = strrchr(name, '/');
283+ FString directoryName = "/";
284+
285+ if (directory != NULL)
286+ {
287+ directoryName = name.Left(ULONG(directory - name.GetChars()));
288+ }
289+
290+ // [AK] Check if we're in the same directory. If not, clear the list of old lump names.
291+ if ((currentDirectory.IsEmpty()) || (currentDirectory.CompareNoCase(directoryName) != 0))
292+ {
293+ oldNames.Clear();
294+ currentDirectory = directoryName;
295+ }
296+
297+ // [AK] Check for any duplicate lumps in the current directory.
298+ for (int i = oldNames.Size() - 1; i > -1; i--)
299+ {
300+ if (oldNames[i].CompareNoCase(name) == 0)
301+ {
302+ if (!quiet) Printf(TEXTCOLOR_YELLOW "\n%s: duplicate lump '%s' detected.\n", Filename, name.GetChars());
303+
304+ // [AK] We only want to keep track of duplicate lumps that may cause authentication
305+ // failures if the file is loaded. Therefore, ignore any lumps that aren't part of
306+ // the global or ACS namespaces.
307+ if ((lump_p->Namespace != -1 ) && (lump_p->Namespace != ns_global) && (lump_p->Namespace != ns_acslibrary))
308+ break;
309+
310+ bool addDuplicate = true;
311+
312+ // [AK] To keep the list of duplicate lumps as small as possible, first check if the
313+ // name of the lump isn't already in the list. If nothing was found, then add the
314+ // full name of the lump to it.
315+ for (unsigned int j = 0; j < DuplicateLumps.Size(); j++)
316+ {
317+ if (DuplicateLumps[j].CompareNoCase(lump_p->FullName) == 0)
318+ {
319+ addDuplicate = false;
320+ break;
321+ }
322+ }
323+
324+ if (addDuplicate)
325+ {
326+ DuplicateLumps.Push(lump_p->FullName);
327+ }
328+
329+ break;
330+ }
331+ }
332+
333+ // [AK] Add this lump name to the list.
334+ oldNames.Push(name);
287335 lump_p++;
288336 }
289337 // Resize the lump record array to its actual size
diff -r f53521bf7613 -r 1e921845d526 src/w_wad.cpp
--- a/src/w_wad.cpp Fri Jan 22 00:11:36 2021 +0000
+++ b/src/w_wad.cpp Sun Jan 24 20:53:03 2021 +0000
@@ -93,6 +93,9 @@
9393
9494 FWadCollection Wads;
9595
96+// [AK] A list of all duplicate lumps found during startup.
97+TArray<FString> DuplicateLumps;
98+
9699 // PRIVATE DATA DEFINITIONS ------------------------------------------------
97100
98101 // CODE --------------------------------------------------------------------
diff -r f53521bf7613 -r 1e921845d526 src/w_wad.h
--- a/src/w_wad.h Fri Jan 22 00:11:36 2021 +0000
+++ b/src/w_wad.h Sun Jan 24 20:53:03 2021 +0000
@@ -249,4 +249,8 @@
249249
250250 extern FWadCollection Wads;
251251
252+// [AK] A list of all duplicate lumps found during startup.
253+extern TArray<FString> DuplicateLumps;
254+
255+
252256 #endif