-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Description
Bug Description
The Chinese month name arrays in numfmt.go are incorrectly sized and missing December (12月), which causes a panic when
processing Excel files with Japanese locale date formats.
Environment
- Excelize Version: v2.10.0
- Go Version: go1.24.3
- OS: macOS (darwin arm64)
Current Code
In vendor/github.com/xuri/excelize/v2/numfmt.go (line ~5565):
monthNamesChineseNum = []string{"0月", "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月"}
Problem
1. Array has only 12 elements (indices 0-11)
2. Missing "12月" (December)
3. Includes non-existent "0月" (Month 0)
4. When formatting December (month=12), code tries to access index 12 → panic: index out of range [12] with length 12
Stack Trace
panic: runtime error: index out of range [12] with length 12
github.com/xuri/excelize/v2.localMonthsNameChinese3({0x0, 0xed938b200, 0x0}, 0x3)
/vendor/github.com/xuri/excelize/v2/numfmt.go:5988 +0xf4
github.com/xuri/excelize/v2.(*numberFormat).localMonthsName(0x14005c9c4b8, 0x3)
/vendor/github.com/xuri/excelize/v2/numfmt.go:7470 +0x258
github.com/xuri/excelize/v2.(*numberFormat).dateTimesHandler(0x14005c9c4b8, 0x3, ...)
/vendor/github.com/xuri/excelize/v2/numfmt.go:7513 +0x3f8
### Steps to reproduce the issue
1. Create an Excel file with cells containing:
- Japanese locale: [$-ja-JP]d-mmm-yy
- Japanese locale: [$-ja-JP]mmmm-yyyy
- Date value: December 1, 2021
2. Use excelize to read cell values:
```golang
f, err := excelize.OpenFile("test.xlsx")
rows, err := f.Rows("Sheet1")
for rows.Next() {
row, err := rows.Columns() // Panics here for December dates
}Sample Excel Format Codes That Trigger the Bug
- [$-ja-JP]d-mmm-yy → "1-Dec-21"
- [$-ja-JP]d-mmm → "1-Dec"
- [$-ja-JP]mmm-yy → "Dec-21"
- [$-ja-JP]dddd, mmmm dd, yyyy → "Wednesday, December 01, 2021"
- [$-ja-JP]mmmm-yyyy → "December-2021"
Describe the results you received
Panic with "index out of range [12] with length 12" when reading Excel cells containing Japanese locale date formats
with month names (mmm/mmmm) for December dates.
The application crashes at localMonthsNameChinese3 function in numfmt.go:5988 when trying to format December (month=12),
because the array only has 12 elements (indices 0-11) and is missing "12月".
Example formats that cause the panic:
[$-ja-JP]d-mmm-yy[$-ja-JP]mmmm-yyyy[$-ja-JP]dddd, mmmm dd, yyyy
Stack trace:
panic: runtime error: index out of range [12] with length 12
github.com/xuri/excelize/v2.localMonthsNameChinese3
github.com/xuri/excelize/v2.(*numberFormat).localMonthsName
github.com/xuri/excelize/v2.(*numberFormat).dateTimesHandler
Describe the results you expected
The cell value should be formatted correctly without panic.
For a cell with date "December 1, 2021" and format [$-ja-JP]d-mmm-yy:
- Expected: "1-12月-21" or "1-Dec-21" (depending on locale conversion)
- Actual: Application crashes with index out of range panic
The month name arrays should include all 12 months (January through December). Since Excel uses 1-based month numbering
(1=January, 12=December), the array should either:
- Have 13 elements with index 0 unused:
{"", "1月", "2月", ..., "12月"} - Have 12 elements with adjusted access code:
monthNamesChineseNum[month-1]
All rows should be readable without crashes, even if they contain December dates with month name formats.
Go version
1.24.3
Excelize version or commit ID
2.10.0
Environment
## Environment
- **Excelize Version**: v2.10.0
- **Go Version**: go1.24.3
- **OS**: macOS (darwin arm64)Validations
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- The provided reproduction is a minimal reproducible example of the bug.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status