Skip to content

Commit 22b36c3

Browse files
committed
Protect against null variable and constant debug information
1 parent d85384d commit 22b36c3

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

Mono.Cecil/AssemblyReader.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2954,14 +2954,20 @@ ScopeDebugInformation ReadLocalScope (Row<uint, Range, Range, uint, uint, uint>
29542954

29552955
if (record.Col2.Length > 0) {
29562956
scope.variables = new Collection<VariableDebugInformation> ((int) record.Col2.Length);
2957-
for (uint i = 0; i < record.Col2.Length; i++)
2958-
scope.variables.Add (ReadLocalVariable (record.Col2.Start + i));
2957+
for (uint i = 0; i < record.Col2.Length; i++) {
2958+
var variable = ReadLocalVariable (record.Col2.Start + i);
2959+
if (variable != null)
2960+
scope.variables.Add (variable);
2961+
}
29592962
}
29602963

29612964
if (record.Col3.Length > 0) {
29622965
scope.constants = new Collection<ConstantDebugInformation> ((int) record.Col3.Length);
2963-
for (uint i = 0; i < record.Col3.Length; i++)
2964-
scope.constants.Add (ReadLocalConstant (record.Col3.Start + i));
2966+
for (uint i = 0; i < record.Col3.Length; i++) {
2967+
var constant = ReadLocalConstant (record.Col3.Start + i);
2968+
if (constant != null)
2969+
scope.constants.Add (constant);
2970+
}
29652971
}
29662972

29672973
return scope;

0 commit comments

Comments
 (0)