[MAGNOLIA-2653] MagnoliaV2Filter emits bogus and unbalanced sv:value element - may cause StackOverflow on large imports Created: 09/Mar/09  Updated: 23/Jan/13  Resolved: 15/Jun/09

Status: Closed
Project: Magnolia
Component/s: core
Affects Version/s: 3.6.3
Fix Version/s: 4.0.2, 4.1.1

Type: Bug Priority: Major
Reporter: Henryk Paluch Assignee: Fabrizio Giustina
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

JDK1.6, WIn2000 and Suse Linux


Attachments: Text File M2FilterMetaBugTest.java     Text File MAGNOLIA-2653.patch     File MagnoliaV2FilterSvValueFix.diff     File MagnoliaV2FilterTestCase.diff     XML File dms.Test.xml     XML File v2filter-out-14551.xml    
Template:
Patch included:
Yes
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Testcase included:
Yes
Date of First Response:

 Description   

MagnoliaV2Filter (user also when importing repository) data emits bogus sv:value and unbalanced sv:value tag. When importing large repositories (3GB with thousands of Documents) this may cause stack overflow due extreme element nesting:

Caused by: java.lang.StackOverflowError
at java.util.HashMap.get(HashMap.java:300)
at org.apache.jackrabbit.core.xml.NamespaceContext.getURI(NamespaceContext.java:93)
at org.apache.jackrabbit.core.xml.NamespaceContext.getURI(NamespaceContext.java:97)
at org.apache.jackrabbit.core.xml.NamespaceContext.getURI(NamespaceContext.java:97)
at org.apache.jackrabbit.core.xml.NamespaceContext.getURI(NamespaceContext.java:97)
at org.apache.jackrabbit.core.xml.NamespaceContext.getURI(NamespaceContext.java:97)
at org.apache.jackrabbit.core.xml.NamespaceContext.getURI(NamespaceContext.java:97)
at org.apache.jackrabbit.core.xml.NamespaceContext.getURI(NamespaceContext.java:97)
...
(thousands of lines)

It turned out, that this overflow is caused by MagnoliaV2Filter when replacing jcr:primary of MetataData type.

Here is excerpt from input data:

<sv:node sv:name="MetaData">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>mgnl:metaData</sv:value>
</sv:property>
<sv:property sv:name="jcr:created" sv:type="Date">
<sv:value>2009-03-09T12:20:25.822+01:00</sv:value>
</sv:property>

Which is by this filter transormed into:

<sv:node sv:name="MetaData">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>mgnl:metaData</sv:value>
</sv:property>

<sv:value>mgnl:metaData

<sv:property sv:name="jcr:created"
sv:type="Date">
<sv:value>2009-03-09T12:20:25.822+01:00</sv:value>
</sv:property>

There is a clear difference - an spurious (and unclosed) <sv:value>mgnl:metaData element

I'm supposed that its startElement() method is missing somehting like

if (skipProperty && qName.equals("sv:value") )

{ skipValue = true; return; }

I shall try and send possible fix hopefully in few days.



 Comments   
Comment by Henryk Paluch [ 09/Mar/09 ]

Test input file (simple export of Test folder form Documents - dms repository)

Comment by Henryk Paluch [ 09/Mar/09 ]

Simple "Test" - it just calls MagnoliaV2Filter for
MagnoliaV2Filter
on dms.Test.xml

Comment by Henryk Paluch [ 09/Mar/09 ]

Output from M2FilterMetaBugTest (file dms.Test.xml filtered through MagnoliaV2Filter

There is clearly visible defect on MetaData nodes:

...
</sv:property>
<sv:node sv:name="MetaData">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>mgnl:metaData</sv:value>
</sv:property>

<sv:value>mgnl:metaData

<sv:property sv:name="jcr:created"
sv:type="Date">
<sv:value>2009-03-09T12:20:25.822+01:00</sv:value>
</sv:property>
...

Comment by Henryk Paluch [ 10/Mar/09 ]

Junit Test Case to reproduce MagnoliaV2Filter. The input file should be left intact (it contains no versioning elements) - however the output fails contains additional misplaced sv:value - thus this test fails on unpatches MagnoliaV2Filter

NOTE: It's reverse patch - please apply with -R

Comment by Henryk Paluch [ 10/Mar/09 ]

Magnolia 3.6.3 core Patch to fix errornous element in MagnolivaV2Filter also fixes additional whitespace after replace. After applying this patch MagnoliaV2Filter produces exactly 1:1 output for non-versioned input file.

Note: It is not yet exensively tested.

Comment by Philipp Bärfuss [ 23/Mar/09 ]

Thanks for the patch, will apply it to the next bugfix version

Comment by Fabrizio Giustina [ 03/Jun/09 ]

Patch and tests committed in revision 25674 for magnolia 4.1, it's indeed a serious bug.
May worth a backport to 3.6.x and 4.0.x as well.

Comment by Magnolia International [ 03/Jun/09 ]

Reverted commit - will review and reapply patch as soon as 4.1 final is out. Too close to release, sorry.

Generated at Mon Feb 12 03:38:48 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.