-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix StackOverflowException when binary property lists contain cyclic …
…refernces (e.g. dictionary containing itself)
- Loading branch information
Showing
8 changed files
with
103 additions
and
15 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* plist - An open source library to parse and generate property lists | ||
* Copyright (C) 2022 Daniel Dreibrodt | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package com.dd.plist; | ||
|
||
/** | ||
* Keeps track of the stack of parsed objects in a binary property list. | ||
* @author Daniel Dreibrodt | ||
*/ | ||
class ParsedObjectStack { | ||
|
||
private ParsedObjectStack parent; | ||
private int object; | ||
|
||
private ParsedObjectStack(ParsedObjectStack parent, int object) { | ||
this.parent = parent; | ||
this.object = object; | ||
} | ||
|
||
/** | ||
* Creates a new stack containing only the specified object identifier. | ||
* @return The stack. | ||
*/ | ||
public static ParsedObjectStack empty() { | ||
return new ParsedObjectStack(null, -1); | ||
} | ||
|
||
/** | ||
* Tries to push the specified object identifier onto the stack, checking that it is not already on the stack. | ||
* @param obj The object identifier. | ||
* @return The new stack with the added object identifier. | ||
* @throws PropertyListFormatException The stack already contained that object identifier, | ||
* indicating a cyclic reference in the property list. | ||
*/ | ||
public ParsedObjectStack push(int obj) throws PropertyListFormatException { | ||
this.throwIfOnStack(obj); | ||
return new ParsedObjectStack(this, obj); | ||
} | ||
|
||
private void throwIfOnStack(int obj) throws PropertyListFormatException { | ||
if (this.parent != null) { | ||
if (this.object == obj) { | ||
throw new PropertyListFormatException("The given binary property list contains a cyclic reference."); | ||
} | ||
|
||
this.parent.throwIfOnStack(obj); | ||
} | ||
} | ||
} |
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
Binary file added
BIN
+142 Bytes
test-files/github-issue75/crash-1f3b69c098890cb571ff42ef9d490447a2311a9f
Binary file not shown.
Binary file added
BIN
+183 Bytes
test-files/github-issue75/crash-6f9bf5d2f691cf8cb5242f9fead55361ef613fd6
Binary file not shown.
Binary file added
BIN
+166 Bytes
test-files/github-issue75/crash-97e1ffe0eac3ef52bc0dbf1644096fcd7d51b873
Binary file not shown.
Binary file added
BIN
+166 Bytes
test-files/github-issue75/crash-9f563bddda68e2665c8d6423ba92207cb2f83d12
Binary file not shown.
Binary file added
BIN
+331 Bytes
test-files/github-issue75/crash-abaa25b8ea29bc8642d3dadb4771f534831c962f
Binary file not shown.