Bug 152431 - Line count resets to zero after 65535
Summary: Line count resets to zero after 65535
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
7.5.0.0 alpha0+
Hardware: All All
: medium normal
Assignee: BogdanB
URL:
Whiteboard: target:7.6.0
Keywords:
Depends on:
Blocks: Word-Count
  Show dependency treegraph
 
Reported: 2022-12-09 01:09 UTC by Hossein
Modified: 2023-07-10 18:47 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
Text file with 65535 non-blank lines (128.00 KB, text/plain)
2022-12-09 01:09 UTC, Hossein
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Hossein 2022-12-09 01:09:13 UTC
Created attachment 184058 [details]
Text file with 65535 non-blank lines

Description:
In LibreOffice Writer document statistics, the line number can not exceed 65535 and it resets to zero after that. This shows the usage of 16 bit unsigned integer for the line count.

Steps to Reproduce:
1. Create a file containing 65535 non-blank lines. For example:
    for i in {1..65535}; do echo .; done > lines.txt
   Alternatively, you can download and use the attachment (lines.txt) from this issue.
2. Open the file
3. Go to File > Properties > Statistics and click Update. See 65535 in the lines.
4. Add a new non-blank line.
3. Count the statistics again, just like step 3.

Actual Results:
The line count is shown as 0.

Expected Results:
The line count should be 65536. Using a 32 bit unsigend integer can increase the limit to 2^32-1=4,294,967,295 (~4.3 billion) which is much better, and is a good practical limit.

Reproducible: Always


User Profile Reset: No


Additional Info:

Reproducible with the latst LO 7.5 dev master:

Version: 7.6.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 95a3d7733c5b48c99b2b74b06c7eeee718fdcd03
CPU threads: 8; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: threaded
Comment 1 BogdanB 2022-12-09 05:28:14 UTC
Confirm with
Version: 7.6.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 95a3d7733c5b48c99b2b74b06c7eeee718fdcd03
CPU threads: 4; OS: Linux 5.19; UI render: default; VCL: gtk3
Locale: ro-RO (ro_RO.UTF-8); UI: en-US
Calc: threaded

It's reseting to zero after the 65535 line.
Comment 2 Mike Kaganski 2022-12-09 07:13:57 UTC
(In reply to Hossein from comment #0)
> The line count should be 65536. Using a 32 bit unsigend integer can increase
> the limit to 2^32-1=4,294,967,295 (~4.3 billion) which is much better, and
> is a good practical limit.

Please don't use unsigned integers, unless you really have to. 2^31 is not much worse. If you are unhappy with that limitation, use sal_Int64, which is *native* on most contemporary platforms.
Comment 3 Commit Notification 2023-06-05 11:53:33 UTC
Bogdan B committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/2f5bffafe4f653aa4ce86f7a27305587680cba58

tdf#152431 Fix line count resets to zero after 65535

It will be available in 7.6.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 4 BogdanB 2023-07-06 19:44:19 UTC
Hossein, is there more to be done? Or I could mark this as Resolved?
Comment 5 Hossein 2023-07-07 09:24:00 UTC
(In reply to BogdanB from comment #4)
> Hossein, is there more to be done? Or I could mark this as Resolved?
Your patch has fixed the problem, and I set it to RESOLVED/FIXED. On the other hand, I think further tests are needed with huge number of lines. Then, possible problems can be reported in separate issues. 

If you want to further examine other candidates for changes, you can take a look into places that static_cast<sal_Int32>() is used.