Skip to content

Commit 9d336a0

Browse files
committed
[ASTGen/Macros] Ensure 'offset' from plugin response is valid
We see some crashes presumably caused by invalid 'offset' returned from macro plugins. Although we haven't been able to find a reproducer, guard not to generate invalid source location by checking 'offfset' is within the buffer length. rdar://125625879
1 parent 4fd6adb commit 9d336a0

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/ASTGen/Sources/ASTGen/PluginHost.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,10 @@ class PluginDiagnosticsEngine {
349349
guard let bufferBaseAddress = exportedSourceFile.pointee.buffer.baseAddress else {
350350
return nil
351351
}
352+
// Ensure 'offset' is within the buffer.
353+
guard offset <= exportedSourceFile.pointee.buffer.count else {
354+
return nil
355+
}
352356
return BridgedSourceLoc(raw: bufferBaseAddress).advanced(by: offset)
353357
}
354358

0 commit comments

Comments
 (0)