Skip to content

fix x86 crash - #5081

Merged
frank-dong-ms-zz merged 1 commit into
dotnet:masterfrom
frank-dong-ms-zz:fix-x86-crash
May 4, 2020
Merged

fix x86 crash#5081
frank-dong-ms-zz merged 1 commit into
dotnet:masterfrom
frank-dong-ms-zz:fix-x86-crash

Conversation

@frank-dong-ms-zz

@frank-dong-ms-zzfrank-dong-ms-zz commented May 2, 2020

Copy link
Copy Markdown
Contributor

fixes#1216.

TreeEnsembleCombiner has a bug that causing byte array out of range and corrupts heap

@frank-dong-ms-zz
frank-dong-ms-zz requested a review from a team as a code ownerMay 2, 2020 02:22
@codecov

codecovBot commented May 2, 2020

Copy link
Copy Markdown

Codecov Report

Merging #5081 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@ Coverage Diff @@## master #5081 +/- ##
=======================================
Coverage 75.66% 75.66% =======================================
Files 993 993 Lines 178157 178157 Branches 19125 19125 =======================================
+ Hits 134800 134805 +5 + Misses 38136 38134 -2 + Partials 5221 5218 -3 
FlagCoverage Δ
#Debug75.66% <100.00%> (+<0.01%)⬆️
#production71.64% <100.00%> (+<0.01%)⬆️
#test88.67% <ø> (ø)
Impacted FilesCoverage Δ
...est/Microsoft.ML.Predictor.Tests/TestPredictors.cs70.07% <ø> (ø)
...t.ML.FastTree/TreeEnsemble/TreeEnsembleCombiner.cs83.09% <100.00%> (ø)
...icrosoft.ML.AutoML/Experiment/SuggestedPipeline.cs88.65% <0.00%> (-4.13%)⬇️
....ML.AutoML/PipelineSuggesters/PipelineSuggester.cs86.55% <0.00%> (-0.85%)⬇️
...soft.ML.Data/DataLoadSave/Text/TextLoaderCursor.cs88.93% <0.00%> (-0.21%)⬇️
...soft.ML.Transforms/Text/WordEmbeddingsExtractor.cs87.52% <0.00%> (ø)
src/Microsoft.ML.Sweeper/AsyncSweeper.cs73.97% <0.00%> (+1.36%)⬆️
...rosoft.ML.AutoML/ColumnInference/TextFileSample.cs65.56% <0.00%> (+5.96%)⬆️

@mstfblmstfbl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean fix! :shipit:

foreach (var t in tree.TrainedEnsemble.Trees)
{
var bytes = new byte[t.SizeInBytes()];
int position = -1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Can you please explain this issue a bit more? Why does this happen in x64 but not in x86? This is managed memory. Why is it corrupting the unamanaged heap?

@frank-dong-ms-zzfrank-dong-ms-zzMay 4, 2020

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is index out of range issue that corrupts memory but this one is index was out of range in former (start to use byte array from index -1)...
This memory corrupted (byte array) is allocated in managed but used as unmanaged (from fixed section in C# and pointer) like below:
https://github.com/dotnet/machinelearning/blob/master/src/Microsoft.ML.FastTree/TreeEnsemble/InternalRegressionTree.cs#L101
https://github.com/dotnet/machinelearning/blob/master/src/Microsoft.ML.FastTree/Utils/ToByteArrayExtensions.cs#L113
when position is -1, the pointer ((int*)(pBuffer + position)) is accessing memory it should not.

I'm still not sure why this issue not repro in x64. In theory this can also corrupt x64 memory.


In reply to: 419011127 [](ancestors = 419011127)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspected this was the issue from reading above, but special thanks to @stephentoub for finding the actual code that proves it 👍

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eerhardt also confirmed this in email.
@sharwell, @stephentoub and @eerhardt Thanks for shedding more light on the issue.

@frank-dong-ms-zz
frank-dong-ms-zz merged commit 2a85f3f into dotnet:masterMay 4, 2020
@ghostghost locked as resolved and limited conversation to collaborators Mar 18, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Investigate why two predictor tests fail with "Unknown command: 'train'" on x86

5 participants

@frank-dong-ms-zz@sharwell@harishsk@mstfbl@frank-dong-ms