-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix infinite loop with bad section ends in TastyHeaderUnpickler #25676
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
Open
SolalPirelli
wants to merge
14
commits into
scala:main
Choose a base branch
from
dotty-staging:s/m9
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7b8ef4c
Fix infinite loop with bad section ends in TastyHeaderUnpickler
SolalPirelli cd1c657
Alternative approach
SolalPirelli 9bf00eb
Check all overflows
SolalPirelli cd5262f
Improve errors
SolalPirelli 03b4a4c
ok..
SolalPirelli 761d624
debug in CI cause I cannot repro this locally properly
SolalPirelli fe47111
ok
SolalPirelli daae9a2
One more
SolalPirelli b2e642b
More fixes
SolalPirelli fba5469
Apply suggestion from @SolalPirelli
SolalPirelli 0060f56
Apply suggestion from @SolalPirelli
SolalPirelli d9c4b3c
Apply suggestion from @SolalPirelli
SolalPirelli 20c236d
PR feedback
SolalPirelli 92e9be5
Apply suggestion from @SolalPirelli
SolalPirelli 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
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -188,7 +188,7 @@ class TreeUnpickler(reader: TastyReader, | |
| if (tag >= firstLengthTreeTag) goto(readEnd()) | ||
| else if (tag >= firstNatASTTreeTag) { readNat(); skipTree() } | ||
| else if (tag >= firstASTTreeTag) skipTree() | ||
| else if (tag >= firstNatTreeTag) readNat() | ||
| else if (tag >= firstNatTreeTag) readLongInt() | ||
|
Contributor
Author
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. these two calls used to be equivalent because we didn't check that it was really a nat or really not a long |
||
| } | ||
| def skipTree(): Unit = skipTree(readByte()) | ||
|
|
||
|
|
@@ -225,7 +225,7 @@ class TreeUnpickler(reader: TastyReader, | |
| if (mode == MemberDefsOnly) skipTree(tag) | ||
| else if (tag >= firstLengthTreeTag) { | ||
| val end = readEnd() | ||
| var nrefs = numRefs(tag) | ||
| val nrefs = numRefs(tag) | ||
| if (nrefs < 0) { | ||
| for (i <- nrefs until 0) scanTree(buf) | ||
| goto(end) | ||
|
|
@@ -241,7 +241,7 @@ class TreeUnpickler(reader: TastyReader, | |
| } | ||
| else if (tag >= firstNatASTTreeTag) { readNat(); scanTree(buf) } | ||
| else if (tag >= firstASTTreeTag) scanTree(buf) | ||
| else if (tag >= firstNatTreeTag) readNat() | ||
| else if (tag >= firstNatTreeTag) readLongInt() | ||
|
Contributor
Author
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. same as above |
||
| } | ||
| } | ||
|
|
||
|
|
||
59 changes: 59 additions & 0 deletions
59
compiler/test/dotty/tools/dotc/core/tasty/TastyUnpickerTest.scala
This file contains hidden or 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,59 @@ | ||
| package dotty.tools.dotc.core.tasty | ||
|
|
||
| import dotty.tools.io.VirtualFile | ||
| import dotty.tools.dotc.core.Contexts.* | ||
| import dotty.tools.dotc.ast.* | ||
| import dotty.tools.dotc.ast.tpd.* | ||
| import dotty.tools.tasty.UnpickleException | ||
| import org.junit.Test | ||
| import org.junit.Assert.* | ||
|
|
||
| class TastyUnpickerTest { | ||
| private def test(bytes: Int*): Unit = | ||
| val base = new ContextBase | ||
| given Context = base.initialCtx.fresh | ||
| val bytesArray = bytes.map(_.toByte).toArray | ||
| val dotty = new DottyUnpickler( | ||
| tastyFile = new VirtualFile("bytes.tasty", bytesArray), | ||
| bytes = bytesArray, | ||
| isBestEffortTasty = false | ||
| ) | ||
| dotty.enter(roots = Set.empty) | ||
| dotty.rootTrees.foreach(t => t.foreachSubTree(identity)) | ||
|
|
||
| // this used to go into an infinite loop as we could 'goto' a negative number when looking for a section end | ||
| @Test def regressionInfiniteLoop(): Unit = | ||
| assertThrows(classOf[UnpickleException], () => test( | ||
| 0x5c, 0xa1, 0xab, 0x1f, 0x9c, 0x88, 0x80, 0xb8, 0x53, 0x63, 0x61, 0x6c, 0x61, 0x20, 0x33, 0x2e, 0x38, 0x2e, 0x32, 0x2d, | ||
| 0x52, 0x43, 0x31, 0x2d, 0x62, 0x69, 0x6e, 0x2d, 0x53, 0x4e, 0x41, 0xb0, 0xac, 0xb7, 0xa9, 0x54, 0x2d, 0x6e, 0x6f, 0x6e, | ||
| 0x62, 0x9a, 0x90, 0x8b, 0x8c, 0x74, 0x72, 0x0a, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6f, 0x6f, 0x6c, 0x77, 0x2e, | ||
| 0x64, 0x6f, 0x74, 0x3c, 0x00, 0xd5, 0x86, 0x0a, 0xd0, 0x5b, 0x65, 0xe8, 0x00, 0xd4, 0x9d, 0xda, 0xab, 0x1f, 0x3b, 0x18, | ||
| 0x02, 0xb6, 0x01, 0x84, 0x41, 0x53, 0x54, 0x73, 0x01, 0x85, 0x7a, 0x63, 0x61, 0x6c, 0x61, 0x01, 0x8a, 0x61, 0x6e, 0x6e, | ||
| 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x02, 0x82, 0x81, 0x82, 0x01, 0x8c, 0x65, 0x78, 0x70, 0x65, 0x72, 0x69, 0x93, | ||
| 0x9a, 0x91, 0x8b, 0x61, 0x6c, 0x01, 0x88, 0x6c, 0x5d, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x01, 0x8f, 0x63, 0x61, 0x70, | ||
| 0x74, 0x75, 0x72, 0x65, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x69, 0x6e, 0x67, 0x01, 0x86, 0x75, 0x6e, 0x72, 0x6f, 0x6c, 0x6c, | ||
| 0x01, 0x86, 0x3c, 0x69, 0x6e, 0x69, 0x74, 0x3e, 0x01, 0x8a, 0x41, 0x6e, 0x6e, 0x6f, 0x69, 0x61, 0x74, 0x74, 0x6f, 0x6e, | ||
| 0x02, 0x82, 0x83, 0x89, 0x3f, 0x82, 0x88, 0x8a, 0x01, 0x90, 0x53, 0x74, 0x61, 0x74, 0x69, 0x63, 0x41, 0x6e, 0x6e, 0x6e, | ||
| 0x69, 0x0b, 0x00, 0x6f, 0x6f, 0x61, 0x01, 0x84, 0x55, 0x6e, 0x69, 0x74, 0x01, 0x8a, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, | ||
| 0x46, 0x69, 0x6c, 0x65, 0x01, 0x88, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x02, 0x82, 0x83, 0x8f, 0x02, 0x82, | ||
| 0x90, 0x8e, 0x01, 0x84, 0x6a, 0x61, 0x76, 0x61, 0x01, 0x84, 0x6c, 0x61, 0x6e, 0x67, 0x02, 0x82, 0x92, 0x93, 0x01, 0x86, | ||
| 0x53, 0x5d, 0x72, 0x69, 0x6c, 0x67, 0x02, 0x82, 0x94, 0x95, 0x3f, 0x83, 0x88, 0x91, 0x96, 0x01, 0xa9, 0x6c, 0x69, 0x62, | ||
| 0x72, 0x61, 0x72, 0x79, 0x2f, 0x73, 0x72, 0x63, 0x2f, 0x73, 0x63, 0x61, 0x6c, 0x61, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, | ||
| 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x75, 0x6e, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x73, 0x63, 0x61, 0x6c, 0x61, 0x02, 0x82, | ||
| 0x83, 0x84, 0x3f, 0x83, 0x88, 0x99, 0x96, 0x01, 0x9e, 0x75, 0x6e, 0x64, 0xa3, 0x8d, 0xdf, 0x8d, 0x9a, 0x89, 0x96, 0x9a, | ||
| 0x77, 0x20, 0x61, 0x73, 0x20, 0x70, 0x61, 0x72, 0x74, 0x20, 0x6f, 0x66, 0x20, 0x53, 0x49, 0x50, 0x2d, 0x34, 0x36, 0x01, | ||
| 0x89, 0x50, 0x6f, 0xd7, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x01, 0x88, 0x41, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x73, | ||
| 0x01, 0x8a, 0x41, 0x74, 0x74, 0x72, 0x69, 0x62, 0x81, 0x74, 0x6d, 0x72, 0x80, 0xd5, 0x84, 0x83, 0x72, 0xdd, 0x2e, 0x47, | ||
| 0xe1, 0x13, 0x24, 0x38, 0x40, 0x40, 0x81, 0x4b, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x86, 0x86, | ||
| 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x0f, 0x0f, 0x09, 0x09, 0x09, 0x09, | ||
| 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, | ||
| 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 0x00, 0x00, 0x9e, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, | ||
| 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, | ||
| 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, | ||
| 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, | ||
| 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, | ||
| 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, | ||
| 0x7f, 0x85, 0x02, 0x03, 0x04, 0x81, 0x98, | ||
| ) ) | ||
| } |
This file contains hidden or 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,3 @@ | ||
| package dotty.tools.tasty | ||
|
|
||
| class PickleException(msg: String) extends RuntimeException(msg) |
This file contains hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.