Skip to content

Commit 498d0c3

Browse files
committed
QL: Convert various int getters to float (to avoid overflow) and correctly handle '-1' padding.
1 parent b738c26 commit 498d0c3

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

ql/ql/src/codeql_ql/StructuredLogs.qll

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class Object extends JSON::Object {
1313

1414
int getNumber(string key) { result = this.getValue(key).(JSON::Number).getValue().toInt() }
1515

16+
float getFloat(string key) { result = this.getValue(key).(JSON::Number).getValue().toFloat() }
17+
1618
Array getArray(string key) { result = this.getValue(key) }
1719

1820
Object getObject(string key) { result = this.getValue(key) }
@@ -31,9 +33,20 @@ class Array extends JSON::Array {
3133

3234
int getNumber(int i) { result = this.getChild(i).(JSON::Number).getValue().toInt() }
3335

36+
float getFloat(int i) { result = this.getChild(i).(JSON::Number).getValue().toFloat() }
37+
3438
Array getArray(int i) { result = this.getChild(i) }
3539
}
3640

41+
/**
42+
* Gets the i'th non-negative number in `a`.
43+
*
44+
* This is needed because the evaluator log is padded with -1s in some cases.
45+
*/
46+
private float getRanked(Array a, int i) {
47+
result = rank[i + 1](int j, float f | f = a.getFloat(j) and f >= 0 | f order by j)
48+
}
49+
3750
module EvaluatorLog {
3851
class Entry extends Object { }
3952

@@ -86,21 +99,21 @@ module EvaluatorLog {
8699

87100
string getRAReference() { result = this.getString("raReference") }
88101

89-
int getCount(int i) { result = this.getArray("counts").getNumber(i) }
102+
float getCount(int i) { result = getRanked(this.getArray("counts"), i) }
90103

91-
int getDuplicationPercentage(int i) {
92-
result = this.getArray("duplicationPercentages").getNumber(i)
104+
float getDuplicationPercentage(int i) {
105+
result = getRanked(this.getArray("duplicationPercentages"), i)
93106
}
94107

95-
int getResultSize() { result = this.getNumber("resultSize") }
108+
float getResultSize() { result = this.getFloat("resultSize") }
96109
}
97110

98111
class PredicateCompleted extends Entry {
99112
PredicateCompleted() { this.getType() = "PREDICATE_COMPLETED" }
100113

101114
int getStartEvent() { result = this.getNumber("startEvent") }
102115

103-
int getResultSize() { result = this.getNumber("resultSize") }
116+
float getResultSize() { result = this.getFloat("resultSize") }
104117
}
105118

106119
class QueryCompleted extends Entry {
@@ -118,7 +131,7 @@ module EvaluatorLog {
118131
class CacheLookup extends Entry {
119132
CacheLookup() { this.getType() = "CACHE_LOOKUP" }
120133

121-
int getRelationSize() { result = this.getNumber("relationSize") }
134+
float getRelationSize() { result = this.getFloat("relationSize") }
122135
}
123136

124137
class SentinelEmpty extends Entry {
@@ -214,7 +227,7 @@ module KindPredicatesLog {
214227
)
215228
}
216229

217-
int getResultSize() { result = this.getNumber("resultSize") }
230+
float getResultSize() { result = this.getFloat("resultSize") }
218231
}
219232

220233
class SentinelEmpty extends SummaryEvent {
@@ -230,9 +243,11 @@ module KindPredicatesLog {
230243

231244
string getRAReference() { result = this.getString("raReference") }
232245

233-
Array getCounts() { result = this.getArray("counts") }
246+
float getCount(int i) { result = getRanked(this.getArray("counts"), i) }
234247

235-
Array getDuplicationPercentages() { result = this.getArray("duplicationPercentages") }
248+
float getDuplicationPercentage(int i) {
249+
result = getRanked(this.getArray("duplicationPercentages"), i)
250+
}
236251
}
237252

238253
class PipeLineRuns extends Array {
@@ -245,9 +260,23 @@ module KindPredicatesLog {
245260
PipeLineRun getRun(int i) { result = this.getObject(i) }
246261
}
247262

263+
class Depencencies extends Object {
264+
SummaryEvent event;
265+
266+
Depencencies() { event.getObject("dependencies") = this }
267+
268+
SummaryEvent getEvent() { result = event }
269+
270+
predicate hasEntry(string name, string hash) { this.getString(name) = hash }
271+
272+
SummaryEvent getADependency() { this.getString(_) = result.getRAHash() }
273+
}
274+
248275
class ComputeSimple extends SummaryEvent {
249276
ComputeSimple() { evaluationStrategy = "COMPUTE_SIMPLE" }
250277

278+
Depencencies getDependencies() { result = this.getObject("dependencies") }
279+
251280
PipeLineRun getPipelineRun() { result.getArray() = this.getArray("pipelineRuns") }
252281
}
253282

0 commit comments

Comments
 (0)