Breaking Type-Safety in Go: An Empirical Study on the Usage of the unsafe Package

06/17/2020
by   Diego Elias Costa, et al.
0

A decade after its first release, the Go programming language has become a major programming language in the development landscape. While praised for its clean syntax and C-like performance, Go also contains a strong static type-system that prevents arbitrary type casting and arbitrary memory access, making the language type-safe by design. However, to give developers the possibility of implementing low-level code, Go ships with a special package called unsafe that offers developers a way around the type-safety of Go programs. The package gives greater flexibility to developers but comes at a higher risk of runtime errors, chances of non-portability, and the loss of compatibility guarantees for future versions of Go. In this paper, we present the first large-scale study on the usage of the unsafe package in 2,438 popular Go projects. Our investigation shows that unsafe is used in 24 operating systems and C code, but is also commonly used as a source of performance optimization. Developers are willing to use unsafe to break language specifications (e.g., string immutability) for better performance and 6 can lead to program crashes and unexpected behavior. Furthermore, we report a series of real issues faced by projects that use unsafe, from crashing errors and non-deterministic behavior to having their deployment restricted from certain popular environments. Our findings can be used to understand how and why developers break type-safety in Go, and help motivate further tools and language development that could make the usage of unsafe in Go even safer.

READ FULL TEXT
research
10/21/2020

Uncovering the Hidden Dangers: Finding Unsafe Go Code in the Wild

The Go programming language aims to provide memory and thread safety thr...
research
08/09/2023

Fixing Rust Compilation Errors using LLMs

The Rust programming language, with its safety guarantees, has establish...
research
03/18/2023

Ownership guided C to Rust translation

Dubbed a safer C, Rust is a modern programming language that combines me...
research
07/01/2020

Is Rust Used Safely by Software Developers?

Rust, an emerging programming language with explosive growth, provides a...
research
08/21/2019

Scala Implicits are Everywhere: A large-scale study of the use of Implicits in the wild

The Scala programming language offers two distinctive language features ...
research
11/27/2012

On the Use of Underspecified Data-Type Semantics for Type Safety in Low-Level Code

In recent projects on operating-system verification, C and C++ data type...
research
12/26/2022

Modular Formal Verification of Rust Programs with Unsafe Blocks

Rust is a modern systems programming language whose type system guarante...

Please sign up or login with your details

Forgot password? Click here to reset