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

fixed AutoFilter record size with multibyte strings. #1367

Open
1 of 5 tasks
htoyama opened this issue Jun 21, 2024 · 3 comments
Open
1 of 5 tasks

fixed AutoFilter record size with multibyte strings. #1367

htoyama opened this issue Jun 21, 2024 · 3 comments
Milestone

Comments

@htoyama
Copy link

htoyama commented Jun 21, 2024

NPOI Version

2.7.0

File Type

  • XLSX
  • XLS
  • DOCX
  • XLSM
  • OTHER

Upload the Excel File

Please attach your original Excel File to help us reproduce the issue

Reproduce Steps

Issue Description

CheckPosition throw exception.
NPOI.Util.RuntimeException: 'Buffer overrun i=4;endIndex=125635;writeIndex=125633'

diff --git a/main/HSSF/Record/AutoFilter/AutoFilterRecord.cs b/main/HSSF/Record/AutoFilter/AutoFilterRecord.cs
index 227a4b1e..c43b9ca6 100644
--- a/main/HSSF/Record/AutoFilter/AutoFilterRecord.cs
+++ b/main/HSSF/Record/AutoFilter/AutoFilterRecord.cs
@@ -130,10 +130,25 @@ protected override int DataSize
             {
                 int recSize = 2 + 2 + 10 + 10;
                 if (field_3_doper1.LengthOfString > 0)
-                    recSize += 1 + field_5_rgch1.Length;
+                    if (rgch1_multibyte)
+                    {
+                        recSize += 1 + (field_5_rgch1.Length * 2); // UTF16LE
+                    }
+                    else
+                    {
+                        recSize += 1 + field_5_rgch1.Length;
+                    }

                 if(field_4_doper2.LengthOfString > 0)
-                    recSize += 1+ field_6_rgch2.Length;
+                    if (rgch2_multibyte)
+                    {
+                        recSize += 1+ (field_6_rgch2.Length * 2); // UTF16LE
+
+                    }
+                    else
+                    {
+                        recSize += 1+ field_6_rgch2.Length;
+                    }
                 return recSize;
             }
         }
@htoyama htoyama added the bug label Jun 21, 2024
@htoyama
Copy link
Author

htoyama commented Jun 21, 2024

Book1.xls
New serialize occur exception.
Workbook.CloneSheet("Sheet1")
Workbook.Write(New_File)

@htoyama htoyama changed the title fixed AutoFileter record size with multibyte strings. fixed AutoFilter record size with multibyte strings. Jun 23, 2024
@wuzxc1230123
Copy link
Contributor

@htoyama You need to provide complete code

@htoyama
Copy link
Author

htoyama commented Aug 27, 2024

I already sent complete code. (1367#issue-2365803303)

@tonyqus tonyqus added this to the NPOI 2.8.0 milestone Oct 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants