Bug 101313 - Copy-paste a Table With Merged Cells from Writer to Calc: Cells Placed in Wrong Position (Wrong cell offsets)
Summary: Copy-paste a Table With Merged Cells from Writer to Calc: Cells Placed in Wro...
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
4.0.0.3 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: target:24.8.0 target:7.6.6 target:24....
Keywords: bibisected, bisected, regression
: 132628 (view as bug list)
Depends on:
Blocks: Paste Calc-Merge-Split
  Show dependency treegraph
 
Reported: 2016-08-05 01:38 UTC by Kevin Suo
Modified: 2024-02-28 15:55 UTC (History)
6 users (show)

See Also:
Crash report or crash signature:


Attachments
this ODT file contains simple tables to reproduce this issue (14.95 KB, application/vnd.oasis.opendocument.text)
2016-08-05 01:38 UTC, Kevin Suo
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Suo 2016-08-05 01:38:55 UTC
Created attachment 126603 [details]
this ODT file contains simple tables to reproduce this issue

The attached ODT file contains a simple table, in which cell "f" is a merged cell.

When copy-paste the table in a Calc file (as formatted RFT text), the cells are placed in wrong position.

It is noted that it works OK when the merged cell is in the first column.

Version: 5.3.0.0.alpha0+
Build ID: 9dc3356f1499a2b90078be86ca7470eb2e96aba8
CPU Threads: 4; OS Version: Windows 6.19; UI Render: default; 
TinderBox: Win-x86@39, Branch:master, Time: 2016-07-21_23:52:45
Locale: zh-CN (zh_CN); Calc: group

Version: 5.2.0.3 (x64)
Build ID: 7dbd85f5a18cfeaf6801c594fc43a5edadc2df0c
CPU Threads: 4; OS Version: Windows 6.19; UI Render: default; 
Locale: zh-CN (zh_CN)

This issue was initially reported in the LibreOffice Chinese Forum: http://www.libreofficechina.org/thread-1542-1-1.html
Comment 1 jmxhyz 2016-08-06 05:34:01 UTC
reproduce:
OS: xubuntu 16.04(x64)
LO: Version: 5.1.4.2
Build ID: 1:5.1.4-0ubuntu1
CPU Threads: 2; OS Version: Linux 4.4; UI Render: default; 
Locale: zh-CN (zh_CN.UTF-8)
Comment 2 Kevin Suo 2017-01-09 04:03:22 UTC
bibisect-release bibisect results suggests that the bug started from libreoffice-4.0.0.0.beta1. Added keyword "regression".
 4f2186cd72652db35eebe5b1b9d3693723433b85 is the first bad commit
commit 4f2186cd72652db35eebe5b1b9d3693723433b85
Author: Matthew Francis <mjay.francis@gmail.com>
Date:   Tue Apr 14 22:40:46 2015 +0800

    libreoffice-4.0.0.0.beta1
    
    LibO-Dev_4.0.0.0.beta1_Linux_x86-64_install-deb_en-US.tar.gz

:040000 040000 e6812e3e351d23e270d6424988196d6208d95b5d 34c7fa1c93970d74dd4dc1bd5706704ffb0b0a9e M	opt

git bisect log
# bad: [e992b5c0217fbbfaed351e4898b8c751ae2fe90e] libreoffice-4.4.7.2
# good: [52afdea50650697a791234f22d2cf2147498b06e] libreoffice-3.3.0
git bisect start 'libreoffice-4.4.7.2' 'libreoffice-3.3.0'
# bad: [33d0c0cac4bfc14221f2a665735e125f446f3251] libreoffice-4.1.3.2
git bisect bad 33d0c0cac4bfc14221f2a665735e125f446f3251
# bad: [4f2186cd72652db35eebe5b1b9d3693723433b85] libreoffice-4.0.0.0.beta1
git bisect bad 4f2186cd72652db35eebe5b1b9d3693723433b85
# good: [4a9bc438d62f90e8bf687683d854c3a044397505] libreoffice-3.5.3rc2
git bisect good 4a9bc438d62f90e8bf687683d854c3a044397505
# good: [ac15b75361b54e9d29f2ed9e3203b731fd0a0d29] libreoffice-3.6.2.2
git bisect good ac15b75361b54e9d29f2ed9e3203b731fd0a0d29
# good: [f4b2466b27f7d7d13b71213a534a8f01dfa1805b] libreoffice-3.6.6.1
git bisect good f4b2466b27f7d7d13b71213a534a8f01dfa1805b
# good: [208dc7bb206c4f313021c2fb045b165638921b9e] libreoffice-3.6.7.1
git bisect good 208dc7bb206c4f313021c2fb045b165638921b9e
# good: [2ba8a27cc4f9f01e531e73760f6c3f6505999be5] libreoffice-3.6.7.2
git bisect good 2ba8a27cc4f9f01e531e73760f6c3f6505999be5
# first bad commit: [4f2186cd72652db35eebe5b1b9d3693723433b85] libreoffice-4.0.0.0.beta1
Comment 3 Kevin Suo 2017-01-09 04:10:23 UTC
Added another "bibisectRequest" keyword, we need someone with the old "43all" bibisect repo to narrow down the range.
Comment 4 Aron Budea 2017-01-22 05:49:58 UTC Comment hidden (bibisection)
Comment 5 Aron Budea 2017-01-22 05:51:17 UTC
This is the range of commits resulting from bibisect with bibisect-43all:
https://cgit.freedesktop.org/libreoffice/core/log/?qt=range&q=50b4cbe94e200288d57a135bc9386012164bc726..27d3fc221d042decbd84b72719107547562d2e12
Comment 6 QA Administrators 2018-11-25 03:40:40 UTC Comment hidden (obsolete)
Comment 7 Roman Kuznetsov 2018-11-25 18:48:34 UTC
still repro in 

Version: 6.2.0.0.beta1 (x64)
Build ID: d1b41307be3f8c19fe6f1938cf056e7ff1eb1d18
CPU threads: 4; OS: Windows 10.0; UI render: GL; VCL: win; 
Locale: ru-RU (ru_RU); UI-Language: en-US
Calc: CL
Comment 8 Kevin Suo 2020-02-01 16:07:13 UTC
Bug still exists in version

版本: 7.0.0.0.alpha0+
Build ID: 0a6ec034dc8088d9de399142bb193ae7d338e645
CPU 线程: 4; 操作系统: Linux 5.4; UI 渲染: 默认; VCL: gtk3; 
区域语言: zh-CN (zh_CN.UTF-8); UI 语言: zh-CN
Calc: threaded
Fedora 31 x64.
Comment 9 Stéphane Guillou (stragu) 2020-08-11 22:03:27 UTC
reproducible in:

Version: 7.0.0.3
Build ID: 8061b3e9204bef6b321a21033174034a5e2ea88e
CPU threads: 8; OS: Linux 4.15; UI render: default; VCL: gtk3
Locale: en-AU (en_AU.UTF-8); UI: en-US
Calc: threaded
Comment 10 Kevin Suo 2022-02-11 12:54:47 UTC
Still reproducible on today's master after the fix for bug 74577.
Comment 11 QA Administrators 2024-02-12 03:12:24 UTC Comment hidden (obsolete)
Comment 12 Kevin Suo 2024-02-13 09:42:13 UTC
Still reproducible on
Version: 24.8.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: ffccbf4762a9ae810bcdd21c41fccdd436e7bfc9
CPU threads: 4; OS: Linux 6.5; UI render: default; VCL: gtk3
Locale: zh-CN (zh_CN.UTF-8); UI: zh-CN
Calc: threaded
Comment 13 Kevin Suo 2024-02-14 16:38:37 UTC
For those who are interested, this may be due to sth wrong in the sc RTF parser  in ScRTFParser::SeekTwips() or ScRTFParser::ColAdjust()
https://opengrok.libreoffice.org/xref/core/sc/source/filter/rtf/rtfparse.cxx?r=4790ef5c
Comment 14 Kevin Suo 2024-02-14 17:45:31 UTC
I have doing some debugging and have found the following, but I don't think I can fix this, so could someone take a look:

The code works for the Writer table like this:
+---+----+----+
|a  |b   |c   |
+---+----+----+
|d       |e   |
+--------+----+

But does not work for a Writer table like this:

+-------+----+----+
|a      |b   |c   |
+---+---+----+----+
|d  |e  |f   |g   |
+---+---+----+----+

The difference between the two tables is that:

- In the first table, the 2nd row contains the merged cell. The right border for *each* of the cells ("d" and "e") has a corresponding aligned border in its top row (i.e. the right border of cells "b" aligns to the right border of cell "d", and the right border of cell "c" aligns to the right border of cell "e"). In such case, ScRTFParser::SeekTwips successfully finds the "nTwips" through the following code, for each of the "d" and "e" cells:

    ScRTFColTwips::const_iterator it = aColTwips.find( nTwips );
    bool bFound = it != aColTwips.end();
    sal_uInt16 nPos = it - aColTwips.begin();
    *pCol = static_cast<SCCOL>(nPos);
    if ( bFound )
        return true;

-- In the second table, the 1st row contains the merged cell. The right border of "d" in the 2nd row does not have a corresponding aligned border in the 1st row (i.e. its top row), thus ScRTFParser::SeekTwips failes to find the "nTwips" through:

    ScRTFColTwips::const_iterator it = aColTwips.find( nTwips );
    bool bFound = it != aColTwips.end();
    sal_uInt16 nPos = it - aColTwips.begin();
    *pCol = static_cast<SCCOL>(nPos);

so it goes on to:
    SCCOL nCol = *pCol;
    // nCol is insertion position; the next one higher up is there (or not)
    if ( nCol < static_cast<SCCOL>(nCount) && ((aColTwips[nCol] - SC_RTFTWIPTOL) <= nTwips) )
        return true;

*Note* that aColTwips is always the list of right border twips of the cells in the first row, and is not updated upon the rows that followed. (i.e, for the 2nd table, aColTwips always has 3 elements which are the twips of the first row cels).

At this moment *pCol is 3 because after the "find" the iterator is at the aColTwips.end(). the *pCol 3 is then passed to its caller "SeekTwips( pE->nTwips, &nCol )" in ScRTFParser::ColAdjust(), in which the column count grows to 6, and the pasted result in Calc becomes:


+-------+----+----+
|a      |b   |c   |
+-------+---------+---+----+----+
|d                |e  |f   |g   |
+-------+---------+---+----+----+
Comment 15 Kevin Suo 2024-02-16 05:40:31 UTC
After two days of work installing an old EOL Fedora 17 and setting up the build environment, I was able to finally build the old libreoffice code and start bisect based on the bibisected range of 50b4cbe94e200288d57a135bc9386012164bc726..27d3fc221d042decbd84b72719107547562d2e12 shown in comment 5.

This regression is now confirmed to be caused by:

commit ed24564ce11683731b820c29d5a46e073ab7a2a7
Author: Noel Grandin <noel@peralex.com>
Date:   Thu Jul 19 15:22:31 2012 +0200
    SV_DECL_VARARR_SORT(ScRTFColTwips) o3tl::sorted_vector

Adding keyword "bisected".
Adding Noel Grandin to cc: would you please take a look? Thanks in advance.
Comment 16 Kevin Suo 2024-02-16 05:49:15 UTC
*** Bug 132628 has been marked as a duplicate of this bug. ***
Comment 17 Noel Grandin 2024-02-16 17:33:59 UTC
Thanks Kevin for the hard work of bisecting.

Fix is here:  https://gerrit.libreoffice.org/c/core/+/163518
Comment 18 Commit Notification 2024-02-16 19:35:39 UTC
Noel Grandin committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/4df426e429e1aed92f074d8acd3ba3a5ec335ba9

tdf#101313 Copy-paste table from writer to calc

It will be available in 24.8.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 19 Commit Notification 2024-02-17 19:16:58 UTC
Noel Grandin committed a patch related to this issue.
It has been pushed to "libreoffice-7-6":

https://git.libreoffice.org/core/commit/034f6c29c309561e75719142c305245ac19f7ba9

tdf#101313 Copy-paste table from writer to calc

It will be available in 7.6.6.

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 20 Commit Notification 2024-02-17 19:17:01 UTC
Noel Grandin committed a patch related to this issue.
It has been pushed to "libreoffice-24-2":

https://git.libreoffice.org/core/commit/b5a5cae0e78e989c421a376bb55a724981c74d87

tdf#101313 Copy-paste table from writer to calc

It will be available in 24.2.2.

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 21 Kevin Suo 2024-02-18 12:37:51 UTC
Verified fixed on master.
Comment 22 Commit Notification 2024-02-19 13:01:21 UTC
Xisco Fauli committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/d0ced35e7a3e2921febe6dacc42fa5d1390b2846

tdf#101313: sw: Add UItest

It will be available in 24.8.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 23 Commit Notification 2024-02-22 20:22:45 UTC
Noel Grandin committed a patch related to this issue.
It has been pushed to "libreoffice-24-2-1":

https://git.libreoffice.org/core/commit/7564f8651012ed0cbfbe6d37cd4effba308a2cd4

tdf#101313 Copy-paste table from writer to calc

It will be available in 24.2.1.

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.