-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
OpenFileGDB: be robust to unusual .gdbindexes files with weird/corrupted/not-understood entries #11372
Merged
Merged
OpenFileGDB: be robust to unusual .gdbindexes files with weird/corrupted/not-understood entries #11372
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file added
BIN
+370 Bytes
autotest/ogr/data/filegdb/corrupted_gdbindexes.gdb/a00000001.gdbtable
Binary file not shown.
Binary file added
BIN
+4.03 KB
autotest/ogr/data/filegdb/corrupted_gdbindexes.gdb/a00000001.gdbtablx
Binary file not shown.
Binary file added
BIN
+2.04 KB
autotest/ogr/data/filegdb/corrupted_gdbindexes.gdb/a00000002.gdbtable
Binary file not shown.
Binary file added
BIN
+4.03 KB
autotest/ogr/data/filegdb/corrupted_gdbindexes.gdb/a00000002.gdbtablx
Binary file not shown.
Binary file added
BIN
+564 Bytes
autotest/ogr/data/filegdb/corrupted_gdbindexes.gdb/a00000003.gdbtable
Binary file not shown.
Binary file added
BIN
+4.03 KB
autotest/ogr/data/filegdb/corrupted_gdbindexes.gdb/a00000003.gdbtablx
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+4.03 KB
autotest/ogr/data/filegdb/corrupted_gdbindexes.gdb/a00000004.gdbtablx
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+4.03 KB
autotest/ogr/data/filegdb/corrupted_gdbindexes.gdb/a00000005.gdbtablx
Binary file not shown.
Binary file added
BIN
+302 Bytes
autotest/ogr/data/filegdb/corrupted_gdbindexes.gdb/a00000006.gdbtable
Binary file not shown.
Binary file added
BIN
+4.03 KB
autotest/ogr/data/filegdb/corrupted_gdbindexes.gdb/a00000006.gdbtablx
Binary file not shown.
Binary file added
BIN
+2.25 KB
autotest/ogr/data/filegdb/corrupted_gdbindexes.gdb/a00000007.gdbtable
Binary file not shown.
Binary file added
BIN
+4.03 KB
autotest/ogr/data/filegdb/corrupted_gdbindexes.gdb/a00000007.gdbtablx
Binary file not shown.
Binary file added
BIN
+460 Bytes
autotest/ogr/data/filegdb/corrupted_gdbindexes.gdb/a00000009.gdbindexes
Binary file not shown.
Binary file added
BIN
+134 Bytes
autotest/ogr/data/filegdb/corrupted_gdbindexes.gdb/a00000009.gdbtable
Binary file not shown.
Binary file added
BIN
+5.03 KB
autotest/ogr/data/filegdb/corrupted_gdbindexes.gdb/a00000009.gdbtablx
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2537,6 +2537,7 @@ int FileGDBTable::GetIndexCount() | |
CPLDebug("OpenFileGDB", ".gdbindexes v9 not handled yet"); | ||
return 0; | ||
} | ||
|
||
returnErrorAndCleanupIf(nIndexCount >= | ||
static_cast<size_t>(GetFieldCount() + 1) * 10, | ||
VSIFree(pabyIdx)); | ||
|
@@ -2547,7 +2548,7 @@ int FileGDBTable::GetIndexCount() | |
returnErrorAndCleanupIf(static_cast<GUInt32>(pabyEnd - pabyCur) < | ||
sizeof(GUInt32), | ||
VSIFree(pabyIdx)); | ||
GUInt32 nIdxNameCarCount = GetUInt32(pabyCur, 0); | ||
const GUInt32 nIdxNameCarCount = GetUInt32(pabyCur, 0); | ||
pabyCur += sizeof(GUInt32); | ||
returnErrorAndCleanupIf(nIdxNameCarCount > 1024, VSIFree(pabyIdx)); | ||
returnErrorAndCleanupIf(static_cast<GUInt32>(pabyEnd - pabyCur) < | ||
|
@@ -2557,13 +2558,56 @@ int FileGDBTable::GetIndexCount() | |
ReadUTF16String(pabyCur, nIdxNameCarCount)); | ||
pabyCur += 2 * nIdxNameCarCount; | ||
|
||
// 4 "magic fields" | ||
returnErrorAndCleanupIf(static_cast<GUInt32>(pabyEnd - pabyCur) < | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not follow: if the comparison is between a sum of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. addressed in #11410 |
||
sizeof(GUInt16) + sizeof(GUInt32) + | ||
sizeof(GUInt16) + sizeof(GUInt32), | ||
VSIFree(pabyIdx)); | ||
// const GUInt16 nMagic1 = GetUInt16(pabyCur, 0); | ||
const GUInt32 nMagic2 = GetUInt32(pabyCur + sizeof(GUInt16), 0); | ||
const GUInt16 nMagic3 = | ||
GetUInt16(pabyCur + sizeof(GUInt16) + sizeof(GUInt32), 0); | ||
if (!((nMagic2 == 2 && nMagic3 == 0) || | ||
(nMagic2 == 4 && nMagic3 == 0) || | ||
(nMagic2 == 16 && nMagic3 == 65535))) | ||
{ | ||
// Cf files a00000029.gdbindexes, a000000ea.gdbindexes, a000000ed.gdbindexes, | ||
// a000000f8.gdbindexes, a000000fb.gdbindexes, a00000103.gdbindexes | ||
// from https://github.com/OSGeo/gdal/issues/11295#issuecomment-2491158506 | ||
CPLDebug("OpenFileGDB", "Reading %s", pszIndexesName); | ||
CPLDebug( | ||
"OpenFileGDB", | ||
"Strange (deleted?) index descriptor at index %u of name %s", i, | ||
osIndexName.c_str()); | ||
|
||
// Skip magic fields | ||
pabyCur += sizeof(GUInt16); | ||
|
||
const GUInt32 nColNameCarCount = nMagic2; | ||
pabyCur += sizeof(GUInt32); | ||
returnErrorAndCleanupIf(nColNameCarCount > 1024, VSIFree(pabyIdx)); | ||
returnErrorAndCleanupIf(static_cast<GUInt32>(pabyEnd - pabyCur) < | ||
2 * nColNameCarCount, | ||
VSIFree(pabyIdx)); | ||
pabyCur += 2 * nColNameCarCount; | ||
|
||
// Skip magic field | ||
returnErrorAndCleanupIf(static_cast<GUInt32>(pabyEnd - pabyCur) < | ||
sizeof(GUInt16), | ||
VSIFree(pabyIdx)); | ||
pabyCur += sizeof(GUInt16); | ||
|
||
continue; | ||
} | ||
|
||
// Skip magic fields | ||
pabyCur += 2 + 4 + 2 + 4; | ||
pabyCur += sizeof(GUInt16) + sizeof(GUInt32) + sizeof(GUInt16) + | ||
sizeof(GUInt32); | ||
|
||
returnErrorAndCleanupIf(static_cast<GUInt32>(pabyEnd - pabyCur) < | ||
sizeof(GUInt32), | ||
VSIFree(pabyIdx)); | ||
GUInt32 nColNameCarCount = GetUInt32(pabyCur, 0); | ||
const GUInt32 nColNameCarCount = GetUInt32(pabyCur, 0); | ||
pabyCur += sizeof(GUInt32); | ||
returnErrorAndCleanupIf(nColNameCarCount > 1024, VSIFree(pabyIdx)); | ||
returnErrorAndCleanupIf(static_cast<GUInt32>(pabyEnd - pabyCur) < | ||
|
@@ -2574,7 +2618,10 @@ int FileGDBTable::GetIndexCount() | |
pabyCur += 2 * nColNameCarCount; | ||
|
||
// Skip magic field | ||
pabyCur += 2; | ||
returnErrorAndCleanupIf(static_cast<GUInt32>(pabyEnd - pabyCur) < | ||
sizeof(GUInt16), | ||
VSIFree(pabyIdx)); | ||
pabyCur += sizeof(GUInt16); | ||
|
||
auto poIndex = std::make_unique<FileGDBIndex>(); | ||
poIndex->m_osIndexName = osIndexName; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was
Car
actually meant to beChar
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in #11410