Bug 122201 - FILESAVE DOCX Unable edit of unprotected areas in protected doc
Summary: FILESAVE DOCX Unable edit of unprotected areas in protected doc
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium normal
Assignee: Serge Krot (CIB)
URL:
Whiteboard: target:6.2.0.2
Keywords: filter:docx
Depends on: 121304
Blocks: DOCX-Doc-Protection
  Show dependency treegraph
 
Reported: 2018-12-19 15:32 UTC by Serge Krot (CIB)
Modified: 2020-02-05 12:57 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
Original ODT document with text and one additional protected section (6.94 KB, application/vnd.oasis.opendocument.text)
2018-12-19 15:32 UTC, Serge Krot (CIB)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Serge Krot (CIB) 2018-12-19 15:32:15 UTC
Created attachment 147672 [details]
Original ODT document with text and one additional protected section

How to reproduce:
* resave of the attached ODT document (with one protected sections inside) into DOCX
* all content became protected including protected section.
Comment 1 Serge Krot (CIB) 2018-12-20 09:38:44 UTC
Patch development is here:
https://gerrit.libreoffice.org/#/c/65278/
Comment 2 Serge Krot (CIB) 2018-12-20 09:45:43 UTC
Question:

In unit test scenario, I would like to try to edit text inside protected section and outside it, to prove that LO prevents editing if area is protected. Unfortunately my code always allows to modify the text inside the DOM:

Code-1:
        uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
        uno::Reference<text::XText> xText(textDocument->getText(), uno::UNO_QUERY);
        uno::Reference<text::XTextRange> xParagraphInProtectedSection = getParagraphOfText( 1, xText ); 
        xParagraphInProtectedSection->setString(OUString( "New text" ));
        CPPUNIT_ASSERT_EQUAL( OUString( "Old text" ), xText->getString());

Code-2:
    // try to insert some text into protected area
    {
        SwNodeIndex aDocEnd(pDoc->GetNodes().GetEndOfContent());
        SwNodeIndex aDocStart(*aDocEnd.GetNode().StartOfSectionNode(), 3);
        SwPaM aPaM(aDocStart);
        pDoc->getIDocumentContentOperations().InsertString(aPaM, "New text");
    }

    // check if content was not changed
    {
        SwNodeIndex aDocEnd(pDoc->GetNodes().GetEndOfContent());
        SwNodeIndex aDocStart(*aDocEnd.GetNode().StartOfSectionNode(), 3);
        SwNode& rNode = aDocStart.GetNode();
        SwTextNode* pTextNode = rNode.GetTextNode();
        CPPUNIT_ASSERT(pTextNode);
        CPPUNIT_ASSERT_EQUAL(OUString("Old text"), pTextNode->GetText()); 
    }


Any ideas? Is it really possible to use protected areas in UNO interface to prevent modification of the content?
Comment 3 Commit Notification 2018-12-20 18:26:23 UTC
Serge Krot committed a patch related to this issue.
It has been pushed to "libreoffice-6-2":

https://git.libreoffice.org/core/+/63ec2e8d07dff652a68c9dc96859c4c61f26b9df%5E%21

tdf#122201 sw: DOCX: allow editing of unprotected areas in protected doc

It will be available in 6.2.0.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 4 Commit Notification 2019-01-18 18:12:10 UTC
Serge Krot committed a patch related to this issue.
It has been pushed to "libreoffice-6-1":

https://git.libreoffice.org/core/+/46c6c414a6df79575517f5df67510d6f4e3d0128%5E%21

tdf#122201 sw: DOCX: allow editing of unprotected areas in protected doc

It will be available in 6.1.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 5 Commit Notification 2019-01-21 14:28:25 UTC
Thorsten Behrens committed a patch related to this issue.
It has been pushed to "libreoffice-6-1":

https://git.libreoffice.org/core/+/a7fd527ece87a1c25fe0d8a9811fe2b230eeea88%5E%21

Revert "tdf#122201 sw: DOCX: allow editing of unprotected areas in protected doc"

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