swiftlang/swift

[SR-3343] Investigate Array Canaries for withUnsafe operations

开放

#45,931 创建于 2016年12月6日

 (0 条评论) (0 个反应) (0 位负责人)Swift (10,719 个派生)batch import
diagnostics qualitygood first issueimprovementstandard library

仓库指标

星标
 (69,989 个星标)
PR 合并指标
 (平均合并 8天 17小时) (30 天内合并 510 个 PR)

描述

Previous ID SR-3343
Radar rdar://problem/16553648
Original Reporter Gankro (JIRA User)
Type Improvement
Votes 0
Component/s Standard Library
Labels Improvement, DiagnosticsQoI, StarterBug
Assignee abdullah (JIRA)
Priority Medium

md5: c68651c162da6db48a6cc867e161ffe0

Issue Description:

We provide several operations which expose the guts of an Array as an UnsafePointer in a closure. This provides an opportunity for developers to mess up and scribble past the bounds of the Array. As a QoI feature, we should look into opportunistically installing a canary at the end of the Array in debug builds.

Basic idea:

  • At the start of withUnsafeBufferPointer (before the closure is called), check if the array has some slack capacity.

  • If it does, write some specific bit pattern to the extra space (just the last byte?).

  • At the end of withUnsafeBufferPointer (after the closure has been called), check if the bit pattern is in tact. If not, assert that a buffer overflow occurred.

This obviously isn't a robust protection against buffer overflows, but maybe it will catch some programmer errors!

I'm happy to mentor anyone who wishes to work on this.

贡献者指南