[GH-ISSUE #84] Issue with sheet names containing multi-byte (UTF-8) characters #71

Closed
opened 2026-05-05 11:36:27 -06:00 by gitea-mirror · 4 comments
Owner

Originally created by @evanmiller on GitHub (Dec 22, 2016).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/84

Originally assigned to: @jmcnamara on GitHub.

Sheet names longer than 32 bytes are disallowed by libxlsxwriter; however I believe the correct behavior is to disallow sheet names longer than 32 characters.

I am trying to debug a customer issue, and I believe the problem is that sanitized strings which are longer than 32 bytes but shorter than 32 characters are passing my program's internal checks, but then failing to be written out to the spreadsheet.

I'd suggest one of:

  • Using a UTF-8-aware strlen
  • Getting rid of the check entirely
  • Having a better failure mode, i.e. if the check fails use "SheetN" instead of returning NULL from workbook_add_worksheet
Originally created by @evanmiller on GitHub (Dec 22, 2016). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/84 Originally assigned to: @jmcnamara on GitHub. Sheet names longer than 32 bytes are [disallowed](https://github.com/jmcnamara/libxlsxwriter/blob/master/src/workbook.c#L1396) by libxlsxwriter; however I believe the correct behavior is to disallow sheet names longer than 32 *characters*. I am trying to debug a customer issue, and I believe the problem is that sanitized strings which are longer than 32 bytes but shorter than 32 characters are passing my program's internal checks, but then failing to be written out to the spreadsheet. I'd suggest one of: * Using a UTF-8-aware `strlen` * Getting rid of the check entirely * Having a better failure mode, i.e. if the check fails use "SheetN" instead of returning NULL from `workbook_add_worksheet`
gitea-mirror 2026-05-05 11:36:27 -06:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@jmcnamara commented on GitHub (Dec 22, 2016):

This is a bug that I had in the back of my mind and was on my TODO list to fix.

You are correct that the check should be on characters rather than bytes (like in the Perl and Python versions) and it was my intention to add a UTF-8 strlen. That same applies for most other length checks on user supplied data.

The worksheet name check also needs to disallow certain characters in the name: []:*?/\\.

And finally there should be suitable warning around this check as well.

Will fix.

<!-- gh-comment-id:268905958 --> @jmcnamara commented on GitHub (Dec 22, 2016): This is a bug that I had in the back of my mind and was on my TODO list to fix. You are correct that the check should be on characters rather than bytes (like in the Perl and Python versions) and it was my intention to add a UTF-8 strlen. That same applies for most other length checks on user supplied data. The worksheet name check also needs to disallow certain characters in the name: `[]:*?/\\`. And finally there should be suitable warning around this check as well. Will fix.
Author
Owner

@jmcnamara commented on GitHub (Dec 23, 2016):

I've pushed an initial pass at this to the utf8_strlen branch, see commit above, if you'd care to try it out.

You will still have to handle the NULL error condition in your own code.

<!-- gh-comment-id:268933180 --> @jmcnamara commented on GitHub (Dec 23, 2016): I've pushed an initial pass at this to the utf8_strlen branch, see commit above, if you'd care to try it out. You will still have to handle the NULL error condition in your own code.
Author
Owner

@evanmiller commented on GitHub (Dec 23, 2016):

Thanks @jmcnamara. Haven't tested but the patch looks fine to me; I'm looking forward to seeing it integrated.

I'll add NULL handling on my end so that is no problem. It might be useful to have a way to validate worksheet names without actually adding them, so that the error condition can be isolated in client code. lxw_worksheet_name_is_valid or something.

<!-- gh-comment-id:268942688 --> @evanmiller commented on GitHub (Dec 23, 2016): Thanks @jmcnamara. Haven't tested but the patch looks fine to me; I'm looking forward to seeing it integrated. I'll add NULL handling on my end so that is no problem. It might be useful to have a way to validate worksheet names without actually adding them, so that the error condition can be isolated in client code. `lxw_worksheet_name_is_valid` or something.
Author
Owner

@evanmiller commented on GitHub (Dec 26, 2016):

Tested master with client code; this bug is now resolved for me. Thanks @jmcnamara!

<!-- gh-comment-id:269229477 --> @evanmiller commented on GitHub (Dec 26, 2016): Tested `master` with client code; this bug is now resolved for me. Thanks @jmcnamara!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/libxlsxwriter#71
No description provided.