Issue 66693 - sax: wrong usage of the function AddBytes
Summary: sax: wrong usage of the function AddBytes
Status: CLOSED FIXED
Alias: None
Product: xml
Classification: Code
Component: code (show other issues)
Version: OOo 2.0.2
Hardware: PC Linux, all
: P3 Trivial (vote)
Target Milestone: OOo 3.0
Assignee: eric.savary
QA Contact: issues@xml
URL:
Keywords:
: 65027 70495 71515 79121 (view as issue list)
Depends on:
Blocks:
 
Reported: 2006-06-23 15:59 UTC by pmladek
Modified: 2009-07-20 14:51 UTC (History)
4 users (show)

See Also:
Issue Type: PATCH
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments
My proposed fix. (1.66 KB, patch)
2006-06-23 16:00 UTC, pmladek
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this issue.
Description pmladek 2006-06-23 15:59:20 UTC
I investigated the sax code. As a side effect, I found some locations where the
function AddBytes is not used correctly in sax/source/expatwrap/saxwriter.cxx.

I'll attach a patch:

- The first hunk fixes a typo. It is obvious that the author wanted to add four
bytes.

- The second hunk probably is not necessary. I added it just for sure.

- The third hunk fixes a missusage of AddBytes. The problem appeared if
(nCurrentPos + nLen + 1 == SEQUENCESIZE). Then AddBytes called writeSequence 
when the buffer was not full. The one character LINEFEED was added too late.
By other words, AddBytes must be called only when (rPos + nBytesCount >= 
SEQUENCESIZE) and this was not the case because it might happen that 
(nCurrentPos + nLen == SEQUENCESIZE - 1)
Comment 1 pmladek 2006-06-23 16:00:15 UTC
Created attachment 37301 [details]
My proposed fix.
Comment 2 Mathias_Bauer 2006-06-26 15:39:41 UTC
Hi Michael, please take this over.
Comment 3 michael.brauer 2006-07-24 11:21:50 UTC
Thank you for creating this patch.

Regarding the free suggestions:

- The first one seems to be correct.
- I'm not sure about the 2nd and the 3rd one. For the 2nd, the current code
seems to be correct (The buffer always is flushed after bytes have been added,
so there should be enough space for a LF in any case.
- For the third, you say the problem appears if (nCurrentPos + nLen + 1 ==
SEQUENCESIZE). In this case, but in this case, AddBytes is not called at all.
Comment 4 niklas.nebel 2006-10-17 19:57:40 UTC
The first change is important, see issue 70495. Invalid files are written (this
is why I came across this).

For the second change I agree with mib: That check is always done *after*
incrementing nCurrentPos. Adding the check there would only make these semantics
unclear to someone reading the code.

For the third change, the problem with the old code is of course with
nCurrentPos+nLen==SEQUENCESIZE, when the text without linefeed would fit into
the buffer, but AddBytes is called for it. I'm not sure if this can really
happen, or if startDocument is only ever called with an empty buffer. Even then,
it looks like it would only cause an assertion message. It should probably be
changed anyway.
Comment 5 niklas.nebel 2006-10-17 19:58:18 UTC
*** Issue 70495 has been marked as a duplicate of this issue. ***
Comment 6 stephenlee 2007-03-31 13:33:53 UTC
Sorry how to apply the diff to OpenOffice 2.2 under windows?
I am from issue 70495. It has being bothering me so much and I am reluctant to
stop using Calc since version 2.0.
Comment 7 michael.brauer 2007-04-10 18:21:37 UTC
We should be able to at least apply the first patch for 2.3
Comment 8 stephenlee 2007-04-15 18:00:15 UTC
"We should be able to at least apply the first patch for 2.3"

First patch is enough. It seems sax is a core library or something that is not
easy to fix...

Thankyou mib. 

Comment 9 pavel 2007-08-06 11:10:22 UTC
mib: this issue is type PATCH. is the patch ok? Is the target 2.3 still valid?
Comment 10 pavel 2007-08-22 12:01:06 UTC
Moving target because of no reply :-(
Comment 11 niklas.nebel 2007-08-24 17:48:23 UTC
*** Issue 79121 has been marked as a duplicate of this issue. ***
Comment 12 michael.brauer 2008-01-02 12:13:11 UTC
*** Issue 71515 has been marked as a duplicate of this issue. ***
Comment 13 michael.brauer 2008-01-02 13:32:54 UTC
Applied 1st and 3rd patch. 

To verify the issue in SRC680 m241:
- load test.xls from i70495
- add an "a" into cell A2.
- Save the doc in ODS.
Without the patch, the ODS cannot be loaded, with the patch, it can be loaded.
Comment 14 michael.brauer 2008-01-02 13:38:58 UTC
*** Issue 65027 has been marked as a duplicate of this issue. ***
Comment 15 michael.brauer 2008-01-11 11:43:12 UTC
re-assigned
Comment 16 stephenlee 2008-02-14 13:34:44 UTC
mib: Thankyou very much.
Comment 17 eric.savary 2008-02-14 13:46:54 UTC
retargetted to 3.0
Comment 18 eric.savary 2008-04-11 13:52:27 UTC
VERIFIED
Comment 19 thorsten.ziehm 2009-07-20 14:51:54 UTC
This issue is closed automatically and wasn't rechecked in a current version of
OOo. The fixed issue should be integrated in OOo since more than half a year. If
you think this issue isn't fixed in a current version (OOo 3.1), please reopen
it and change the field 'Target Milestone' accordingly.

If you want to download a current version of OOo =>
http://download.openoffice.org/index.html
If you want to know more about the handling of fixed/verified issues =>
http://wiki.services.openoffice.org/wiki/Handle_fixed_verified_issues