---
title: "gocsv: CSV number parsing and a data race in Go | VulCode"
description: "Four changes to gocsv in Go: zero-padded numbers parsed in base 10, SetHeaderNormalizer free of data races, a new marshal function and a fixed date layout."
url: "https://vulcode.com/en/opensource/contributions/gocsv"
lang: "en"
---

[All contributions](https://vulcode.com/en/opensource/contributions)

gocarina/gocsv

# gocsv

A Go library that turns CSV files into structs and structs back into CSV, driven by field tags.

[See the repository](https://github.com/gocarina/gocsv) [All contributions](https://vulcode.com/en/opensource/contributions)

- **Language**: Go
- **GitHub stars**: 2,203
- **Merged changes**: 4

## What we changed

Zero-padded numbers are read in base 10, SetHeaderNormalizer can be called during decoding without a data race, MarshalBytesWithoutHeaders was added, and the README example writes dates in the right layout.

### What this work shows

- Data races and sync/atomic in Go

- Number parsing with strconv

- Date layouts in Go's time package

What was broken

### A leading zero turned a number into octal

toInt and toUint passed the field to strconv with base 0, so a leading zero meant octal. A field of 08 or 09 failed to parse, and 010 silently became 8.

How we fixed it

### Integer fields read in base 10

Both calls now use base 10, so 010 is 10 and 08 is 8. Go-style prefixed values such as 0x1f now return a parse error. Tests cover negative numbers and decoding through UnmarshalString.

[#293](https://github.com/gocarina/gocsv/pull/293)

What was broken

### Changing the normaliser during decoding

SetHeaderNormalizer replaced the struct info cache while other goroutines were still using it. That ended in a panic or a failure under go test -race.

How we fixed it

### Normaliser and cache swapped together

The normaliser and the struct infos built with it now live in one value that is swapped atomically with sync/atomic. A test calls SetHeaderNormalizer alongside UnmarshalString in 50 pairs of goroutines.

[#303](https://github.com/gocarina/gocsv/pull/303)

What was broken

### No MarshalBytes variant without headers

The library had MarshalStringWithoutHeaders but no counterpart that returns []byte. An issue in the project asked for exactly that function.

How we fixed it

### A new MarshalBytesWithoutHeaders function

We added MarshalBytesWithoutHeaders, which writes the rows without a header line and returns bytes, like MarshalBytes. A test checks the exact output.

[#305](https://github.com/gocarina/gocsv/pull/305)

What was broken

### The example wrote dates as year, day, month

The layout 20060201 in Go's time package means year, day and month, so the README example wrote 4 November as 20220411.

How we fixed it

### The right date layout in the examples

We changed the layout to 20060102 in the README and the full example, and the expected output in the example test now shows 20221104.

[#304](https://github.com/gocarina/gocsv/pull/304)

## Merged changes 4

- [#305 Add MarshalBytesWithoutHeaders Merged 12 October 2026](https://github.com/gocarina/gocsv/pull/305)

- [#304 Fix date layout in README and full example Merged 12 October 2026](https://github.com/gocarina/gocsv/pull/304)

- [#303 Make SetHeaderNormalizer safe to call while decoding Merged 12 October 2026](https://github.com/gocarina/gocsv/pull/303)

- [#293 Parse integer fields as base 10 (fixes #182) Merged 5 September 2026](https://github.com/gocarina/gocsv/pull/293)

## What it taught us

A shared cache is a typical place for a data race: an atomic swap removes it, and a test that passes under go test -race guards it. We read spreadsheet data as data, not as Go literals: 010 means ten, not eight.

[More about this technology: Golang](https://vulcode.com/en/technologies/go)

## Other projects we write code for

- [**urfave/cli** Go · 24,329 stars A declarative Go package for building command line tools.](https://vulcode.com/en/opensource/contributions/urfave-cli)

- [**chezmoi** Go · 22,342 stars A dotfiles manager that keeps the same settings on many different machines, securely.](https://vulcode.com/en/opensource/contributions/chezmoi)

- [**goquery** Go · 14,995 stars A Go library for traversing and changing HTML documents in the style of jQuery, built on the golang.org/x/net/html parser.](https://vulcode.com/en/opensource/contributions/goquery)

- [**Ebitengine** Go · 13,647 stars A 2D game engine in Go, used in games released for computers, phones, browsers and consoles.](https://vulcode.com/en/opensource/contributions/ebiten)

- [**Fission** Go · 8,950 stars A serverless functions framework for Kubernetes that runs code as functions and scales them down to zero when they are idle.](https://vulcode.com/en/opensource/contributions/fission)

- [**Concourse** Go · 7,944 stars A container-based automation system written in Go and used mostly for CI/CD. Pipelines and tasks are described in YAML files.](https://vulcode.com/en/opensource/contributions/concourse)

## Describe your project.

A free quote comes back within an hour during working hours.

### Rather skip the form?

Ask in the chat or write to us directly.

Open the chat

- **Email**: [hello@vulcode.com](mailto:hello@vulcode.com)
- **Phone**: [+48 576 043 920](tel:+48576043920)
- **Discord**: [discord.gg/vulcode](https://discord.gg/vulcode)
