Bug 170322 - FILESAVE DOCX Certain documents with content controls can't be opened in Word after roundtrip
Summary: FILESAVE DOCX Certain documents with content controls can't be opened in Word...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: filters and storage (show other bugs)
Version:
(earliest affected)
24.2.1.2 release
Hardware: All All
: medium normal
Assignee: Justin L
URL:
Whiteboard: target:26.8.0 target:26.2.1
Keywords: bibisected, bisected, regression
Depends on:
Blocks: DOCX-Corrupted DOCX-Content_Control
  Show dependency treegraph
 
Reported: 2026-01-13 09:29 UTC by Aron Budea
Modified: 2026-01-20 02:46 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
A Plain text control.docx: with different formatting and multiple w:t runs (19.16 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2026-01-14 17:11 UTC, Justin L
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Aron Budea 2026-01-13 09:29:58 UTC
Open and save attachment 53318 [details] from bug 42736 or attachment 125030 [details] from bug 99822 back to DOCX, then try opening the result in Word.

=> Word fails to open the files cleanly.

If one:
- unzips the saved DOCX,
- executes the following command (can be done in Linux/Cygwin, needs xmllint installed): find . \( -name "*.xml" -o -name "*.rels" \) -type f -exec xmllint --output '{}' --format '{}' \;
- rezips the files with DOCX extension,

Word points to the ending '</w:sdt>' element in the respective XMLs containing the content controls.

This is a regression from the following commit in 24.8 and its backport to 24.2:
https://git.libreoffice.org/core/commit/13a11632014ccc27199667c6a1e313f8ff616d6d
author		Mike Kaganski <mike.kaganski@collabora.com>	Mon Jan 22 19:10:29 2024 +0600
committer	Mike Kaganski <mike.kaganski@collabora.com>	Tue Jan 23 05:33:42 2024 +0100

"tdf#159259: make sure to set FieldStartRange in sdt helper"

Affected bugdocs:
abi13887-1.docx
fdo42736-1.docx
forum-mso-de-88566.docx
forum-mso-de-88567.docx
forum-mso-en-11890.docx
forum-mso-en-12392.docx
forum-mso-en-1852.docx
forum-mso-en-3607.docx
forum-mso-en-4096.docx
lp1193316-1.docx
tdf99822-1.docx
Comment 1 Justin L 2026-01-14 12:18:24 UTC
The problem with 'table_text.docx' is the empty <w:text/> entry. Same with 6.docx.
Comment 2 Justin L 2026-01-14 14:48:30 UTC
(In reply to Justin L from comment #1)
> The problem is the empty <w:text/> entry.
Well that is not exactly true, because w:text is ALWAYS empty.

ChatGPT was helpful here. Apparently there can only be ONE w:r inside a plaintext control. (I.E. all of the content inside is formatted identically - and that makes sense based on the definition of what plaintext is.)

Removing the w:text means it gets treated as a rich text control - so allowed to have multiple 'runs' of formatting - as well as multiple paragraphs etc.
Comment 3 Justin L 2026-01-14 17:11:04 UTC
Created attachment 205047 [details]
A Plain text control.docx: with different formatting and multiple w:t runs

(In reply to Justin L from comment #2)
> Apparently there can only be ONE w:r inside a plaintext control.
That's also not true.

Probably the key here is to force any SDT containing a field to be a richtext control. That would make sense anyway, since anything that contains a field is not 'simple'.
Comment 4 Justin L 2026-01-15 17:46:05 UTC
Should be solved by import-adjusting https://gerrit.libreoffice.org/c/core/+/197300, but when saving I hit a debug assert - so I must have been lucky enough to hit some other content-control export failure. Hurray.
Comment 5 Commit Notification 2026-01-17 01:07:52 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

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

tdf#170322 writerfilter: import fields into richText, not plainText

It will be available in 26.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 6 Commit Notification 2026-01-17 01:08:55 UTC
justin.luth@collabora.com committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/3f4d026f7a2fbc6c5341dbfa69052b6ce82c14df

tdf#170322 docx export: close blockSDT when frame is done

It will be available in 26.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 7 Commit Notification 2026-01-19 20:16:56 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "libreoffice-26-2":

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

tdf#170322 writerfilter: import fields into richText, not plainText

It will be available in 26.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.
Comment 8 Commit Notification 2026-01-20 01:31:25 UTC
justin.luth@collabora.com committed a patch related to this issue.
It has been pushed to "libreoffice-26-2":

https://git.libreoffice.org/core/commit/3c552ee36404717735c1b4fa68ee4e50516592d7

tdf#170322 docx export: close blockSDT when frame is done

It will be available in 26.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.
Comment 9 Commit Notification 2026-01-20 01:40:28 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/2315f0fe9ef1f94634d1a8944203b234170becf7

tdf#170322 docx export: explain why unit test checks for <w:text/>

It will be available in 26.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 10 Commit Notification 2026-01-20 02:46:35 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/52c6bbfc381c37ea6400f768f7d4773da9ba6873

tdf#170322 writerfilter: if dataBinding, then not richText

It will be available in 26.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.