Skip to content

Commit 035d055

Browse files
Fix out-of-bounds access in markUnreachable
1 parent be16d78 commit 035d055

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed
Binary file not shown.
Binary file not shown.

Sources/WasmKit/Translator.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,10 @@ struct InstructionTranslator: InstructionVisitor {
170170
self.frames.popLast()
171171
}
172172

173-
mutating func markUnreachable() {
173+
mutating func markUnreachable() throws {
174+
guard !self.frames.isEmpty else {
175+
throw TranslationError("Control stack is empty. Instruction cannot be appeared after \"end\" of function")
176+
}
174177
self.frames[self.frames.count - 1].reachable = false
175178
}
176179

@@ -457,7 +460,7 @@ struct InstructionTranslator: InstructionVisitor {
457460
iseqBuilder.emit(.return)
458461
}
459462
private mutating func markUnreachable() throws {
460-
controlStack.markUnreachable()
463+
try controlStack.markUnreachable()
461464
let currentFrame = try controlStack.currentFrame()
462465
try valueStack.truncate(height: currentFrame.stackHeight)
463466
}

0 commit comments

Comments
 (0)