google / google/glazier

Config and unattend.xml are read without an encoding, corrupting or crashing on non-ASCII outside a UTF-8 locale

Open
#799 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.3k
Forks
96
Avg merge
3d 15h
Merged PRs (30d)
4

Description

`_YamlReader()` opens every config file without an encoding, so the read uses `locale.getpreferredencoding()`:

```python
# glazier/lib/config/files.py:152
with open(path, 'r') as yaml_file:
yaml_config = yaml.safe_load(yaml_file)
except IOError as e:
raise FileReadError(path) from e
```

That is the path `files.Read()` takes for `build.yaml`, `task_list.yaml`, `release-id.yaml` and `version-info.yaml`, reached from `buildinfo.py`, `config/builder.py:126`, `config/runner.py:57` and `os_selector.py:51`. On a Windows host whose ANSI codepage is cp1252 it has two failure modes, both measured on CPython 3.13.13 through the real `files.Read()`:

```python
# UTF-8 config containing 'café' (bytes 63 61 66 c3 a9)
files.Read(p)['name'] # 'café' - silently wrong, no exception

# UTF-8 config containing a combining acute (bytes 65 cc 81)
files.Read(p)['name']
# UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 ... maps to
```

The second one matters beyond the crash itself: `UnicodeDecodeError` is not an `IOError`, so the `except IOError` clause above does not catch it and it escapes as a raw traceback rather than the module's declared `FileReadError`.

`glazier/lib/actions/sysprep.py:40` and `:46` have the same shape, reading and rewriting `C:\Windows\Panther\unattend.xml` in default text mode, though Sysprep writes that file as UTF-8. Same uncaught `UnicodeDecodeError` there, past the same `except IOError`.

`#26` fixed this class in `lib/actions/files.py` in 2019. These two sites look like they were missed rather than deliberately left.

CI runs `ubuntu-latest` only, where the preferred encoding is UTF-8, so neither site is exercised.

Contributor guide

Open the contributing guide

Research direction

Start with _YamlReader() in glazier/lib/config/files.py and the read/rewrite paths in glazier/lib/actions/sysprep.py. Compare the earlier encoding fix in lib/actions/files.py and trace callers such as buildinfo.py, config/builder.py, config/runner.py, and os_selector.py. Done means non-ASCII UTF-8 config and unattend.xml data are handled correctly without a raw UnicodeDecodeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
operating-systems, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.