bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Long variable value get corrupted sometimes


From: Daniel Qian
Subject: Long variable value get corrupted sometimes
Date: Wed, 16 Feb 2022 16:10:40 +0800

Hi all,

I encountered a problem that long variable value get corrupted sometimes.

OS: Alpine linux 3.15.0 (docker container)
Bash version: GNU bash, version 5.1.8(1)-release (x86_64-alpine-linux-musl)

Reproduction steps:

A UTF-8 encoded file containing a lot of Chinese characters, file size ~35K.

A test script read content from `foo.txt` and assign the content to a variable,
and then check md5sum for that variable.

```bash
#!/bin/bash

FOO=$(cat /tmp/foo.txt)
want_q_md5=$(cat /tmp/foo.txt.md5 | cut -d ' ' -f 1)
got_md5=$(echo "$FOO" | md5sum -b | cut -d ' ' -f 1)
if [[ "$got_md5" != "$want_q_md5" ]]; then
  echo "failed"
  echo "$FOO" > /tmp/foo-corrupt.txt
  fail=true
else
  echo "succeed"
fi
```

**Sometimes**, the md5sum check failed.

Output variable value to `foo-corrupt.txt` when check fail, compare it
with `foo.txt`,
found that a random byte are inserted into multiple positions.

I created a github repo for this issue, all the scripts are there:
https://github.com/chanjarster/bash-5_1_8_long_var_corrupt

-- 
Daniel Qian
Apache Committer(chanjarster)
blog:https://chanjarster.github.io
github:https://github.com/chanjarster
segmentfault: https://segmentfault.com/u/chanjarster



reply via email to

[Prev in Thread] Current Thread [Next in Thread]