invalid SOFA files for UTF-8 strings

Open
#147 5 comments 0 reactions 0 assignees View on GitHub

@f-brinkmann is already working on this.

Since Oct 24, 2026.

  • #149 by @f-brinkmann — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
python
Domain
data

Research direction

Start by reproducing the issue with the netCDF4 example and inspect sofar's writing and validate paths for string attributes. Confirm how UTF-8 descriptions are written and checked, then verify that the resulting SOFA file uses only allowed NC_CHAR attributes and that validation handles invalid NC_STRING attributes correctly.

Written by the indexing model from the issue text.

Description

bug

Following https://github.com/sofacoustics/SOFAtoolbox/issues/95#event-31983840895

I think there is an issue in sofar.

Writing a UTF-8 string as a SOFA description will produce an NC_STRING attribute [due to a fallback in the netcdf4-python backend](https://github.com/Unidata/netcdf4-python/blob/v1.7.3rel/src/netCDF4/_netCDF4.pyx#L1867-L1874.

For example:

"""Show netCDF4 writing a UTF-8 variable attribute as NC_STRING."""
from pathlib import Path

from netCDF4 import Dataset

filename = Path("test.sofa")
with Dataset(filename, "w", format="NETCDF4") as file:
    file.createDimension("S", 1)
    variable = file.createVariable("Data.String", "S1", ("S",))
    variable.AsciiDescription = "ear"
    variable.Utf8Description = "Hörlappen"

ncdump test.sofa gives

netcdf test {
dimensions:
	S = 1 ;
variables:
	char Data.String(S) ;
		Data.String:AsciiDescription = "ear" ;
		string Data.String:Utf8Description = "Hörlappen" ;
data:

 Data.String = "" ;
}

The SOFA standard only allows NC_CHAR attributes so this would create an invalid file. I think this problem is twofold: one in writing to the file and another in validate because sofar happily validates and reads NC_STRING correctly.

Dominant language
Python
Stars
37
Forks
4
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pyfar/sofar

All issues in pyfar/sofar

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.