Skip to content

Commit fa2318a

Browse files
evicyV8-internal LUCI CQ
authored andcommitted
[improve livetests] Limit max generated value of randomNonNegativeIndex()
This helper function is used to generate random indices for memory accesses. In some cases, it calls the randomSize() function which has an upper cap of the generated number which is way larger than the Wasm memory size usually. This was not an issue, as we used the remainder after modulo memory_size. However, as the generated number is uniformly chosen from a set of interesting integers which are close to the multiples of the memory_size, too often we ended up using values close to the memory_size. To fix this issue, we will pass the memory_size to randomSize() as the upper cap, so no multiples are generated, therefore, we will not get the memory_size value often. Change-Id: I157508ee5f9f1a6453de99f8066fd655d67547cb Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/7963788 Reviewed-by: Carl Smith <[email protected]> Commit-Queue: Eva Herencsárová <[email protected]>
1 parent 5b4896a commit fa2318a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Sources/Fuzzilli/Base/ProgramBuilder.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,12 @@ public class ProgramBuilder {
260260
}
261261

262262
/// Returns a random non-negative integer value suitable as index.
263-
public func randomNonNegativeIndex() -> Int64 {
263+
public func randomNonNegativeIndex(upTo max: Int64 = 0x100000000) -> Int64 {
264264
// Prefer small indices.
265265
if probability(0.33) {
266266
return Int64.random(in: 0...10)
267267
} else {
268-
return randomSize()
268+
return randomSize(upTo: max)
269269
}
270270
}
271271

@@ -3484,10 +3484,10 @@ public class ProgramBuilder {
34843484
let function = self.currentWasmModule.currentWasmFunction
34853485

34863486
// Generate an in-bounds offset (dynamicOffset + staticOffset) into the memory.
3487-
let dynamicOffsetValue = self.randomNonNegativeIndex() % memSize
3487+
let dynamicOffsetValue = self.randomNonNegativeIndex(upTo: memSize)
34883488
let dynamicOffset = memoryTypeInfo.isMemory64 ? function.consti64(dynamicOffsetValue)
34893489
: function.consti32(Int32(dynamicOffsetValue))
3490-
let staticOffset = self.randomNonNegativeIndex() % (memSize - dynamicOffsetValue)
3490+
let staticOffset = self.randomNonNegativeIndex(upTo: memSize) % (memSize - dynamicOffsetValue)
34913491

34923492
return (dynamicOffset, staticOffset)
34933493
}

0 commit comments

Comments
 (0)