Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrupted utf-8 cell value if TotalCellChars reached #1518

Closed
IAkumaI opened this issue Apr 10, 2023 · 2 comments
Closed

Corrupted utf-8 cell value if TotalCellChars reached #1518

IAkumaI opened this issue Apr 10, 2023 · 2 comments

Comments

@IAkumaI
Copy link
Contributor

IAkumaI commented Apr 10, 2023

Description

Excel has upper limit of character count which is 32767, but excelize checks value length by bytes instead by characters.
If I put utf-8 value (repeated 17000 times two-bytes symbol "Ы", for example) to a cell, excelize won't show any error, but file will be corrupted. Excel will show error on this file. Mac Numbers doesn't show any error, but empty cell and half-empty file.

I've already created pull request: #1517

Steps to reproduce the issue:

long_value := strings.Repeat("Ы", 17000)
f.SetCellValue("Sheet1", "A1", long_value) // No errors here
// Save file and so on

String long_value contains 17000 chars, but it will go into if len(value) > TotalCellChars because...Go works so. Let's fix it.

Output of go version:

go version go1.19.1 darwin/arm64

Excelize version or commit ID:

v2.7.1

Environment details (OS, Microsoft Excel™ version, physical, etc.):

It doesn't rely on an environment.

@IAkumaI
Copy link
Contributor Author

IAkumaI commented Apr 10, 2023

The worst is that without the fix you can not fix this from outside, because if len(value) > TotalCellChars is true for every utf-8 TotalCellChars/2 len string and next line value[:TotalCellChars] will corrupt the string because you must not slice strings in Go in this way.

@xuri
Copy link
Member

xuri commented Apr 12, 2023

Thanks for your issue. I have merged the pull request #1517 to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants