Return-Path: Delivered-To: apmail-xml-xalan-cvs-archive@www.apache.org Received: (qmail 54816 invoked from network); 27 Jan 2005 15:28:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 27 Jan 2005 15:28:11 -0000 Received: (qmail 41720 invoked by uid 500); 27 Jan 2005 15:28:05 -0000 Delivered-To: apmail-xml-xalan-cvs-archive@xml.apache.org Received: (qmail 41699 invoked by uid 500); 27 Jan 2005 15:28:05 -0000 Mailing-List: contact xalan-cvs-help@xml.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: Delivered-To: mailing list xalan-cvs@xml.apache.org Received: (qmail 41662 invoked by uid 99); 27 Jan 2005 15:28:04 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Thu, 27 Jan 2005 07:28:04 -0800 Received: (qmail 54388 invoked by uid 1538); 27 Jan 2005 15:28:02 -0000 Date: 27 Jan 2005 15:28:02 -0000 Message-ID: <20050127152802.54386.qmail@minotaur.apache.org> From: zongaro@apache.org To: xml-xalan-cvs@apache.org Subject: cvs commit: xml-xalan/java/src/org/apache/xml/dtm/ref/sax2dtm SAX2DTM2.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N zongaro 2005/01/27 07:28:02 Modified: java/src/org/apache/xml/dtm/ref/sax2dtm SAX2DTM2.java Log: Two part fix for Jira bug report XALANJ-1888. 1) It is possible for the characters SAX event to specify a length of zero. Text nodes should not be created in such situations. Changed the charactersFlush method to guard against this case. 2) Made a defensive change to references to m_dataOrQName. If the value in this vector is to be interpreted as an index into m_data, it is stored as a negative value (via calls to addNode). However, most references to elements of m_dataOrQName were checking whether the value was non-positive, treating a value of zero as an index into m_data as well. The zeroth entry into m_data is an invalid entry. The fix to charactersFlush described above should ensure that zero is never stored in m_dataOrQName, but I thought it was just as well to duplicate the interpretation used in storing values in m_dataOrQName. Reviewed by Morris Kwan (mkwan () ca ! ibm ! com) Revision Changes Path 1.15 +30 -29 xml-xalan/java/src/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM2.java Index: SAX2DTM2.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM2.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- SAX2DTM2.java 24 Jan 2005 00:34:36 -0000 1.14 +++ SAX2DTM2.java 27 Jan 2005 15:28:02 -0000 1.15 @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -2399,31 +2399,32 @@ doStrip = m_chars.isWhitespace(m_textPendingStart, length); } - if (doStrip) + if (doStrip) { m_chars.setLength(m_textPendingStart); // Discard accumulated text - else - { - // If the offset and length do not exceed the given limits - // (offset < 2^21 and length < 2^10), then save both the offset - // and length in a bitwise encoded value. - if (length <= TEXT_LENGTH_MAX && m_textPendingStart <= TEXT_OFFSET_MAX) - { - m_previous = addNode(m_coalescedTextType, DTM.TEXT_NODE, + } else { + // Guard against characters/ignorableWhitespace events that + // contained no characters. They should not result in a node. + if (length > 0) { + // If the offset and length do not exceed the given limits + // (offset < 2^21 and length < 2^10), then save both the offset + // and length in a bitwise encoded value. + if (length <= TEXT_LENGTH_MAX + && m_textPendingStart <= TEXT_OFFSET_MAX) { + m_previous = addNode(m_coalescedTextType, DTM.TEXT_NODE, m_parents.peek(), m_previous, length + (m_textPendingStart << TEXT_LENGTH_BITS), false); - } - else - { - // Store the offset and length in the m_data array if one of them - // exceeds the given limits. Use a negative dataIndex as an indication. - int dataIndex = m_data.size(); - m_previous = addNode(m_coalescedTextType, DTM.TEXT_NODE, - m_parents.peek(), m_previous, -dataIndex, false); + } else { + // Store offset and length in the m_data array if one exceeds + // the given limits. Use a negative dataIndex as an indication. + int dataIndex = m_data.size(); + m_previous = addNode(m_coalescedTextType, DTM.TEXT_NODE, + m_parents.peek(), m_previous, -dataIndex, false); - m_data.addElement(m_textPendingStart); - m_data.addElement(length); + m_data.addElement(m_textPendingStart); + m_data.addElement(length); + } } } @@ -2791,7 +2792,7 @@ if (type == DTM.TEXT_NODE || type == DTM.CDATA_SECTION_NODE) { int dataIndex = m_dataOrQName.elementAt(identity); - if (dataIndex > 0) + if (dataIndex >= 0) { if (-1 == offset) { @@ -2830,7 +2831,7 @@ else if (DTM.TEXT_NODE == type || DTM.CDATA_SECTION_NODE == type) { int dataIndex = m_dataOrQName.elementAt(identity); - if (dataIndex > 0) + if (dataIndex >= 0) { if (m_xstrf != null) return m_xstrf.newstr(m_chars, dataIndex >>> TEXT_LENGTH_BITS, @@ -2904,7 +2905,7 @@ if (type == DTM.TEXT_NODE || type == DTM.CDATA_SECTION_NODE) { int dataIndex = m_dataOrQName.elementAt(identity); - if (dataIndex > 0) + if (dataIndex >= 0) { if (-1 == offset) { @@ -2940,7 +2941,7 @@ else if (DTM.TEXT_NODE == type || DTM.CDATA_SECTION_NODE == type) { int dataIndex = m_dataOrQName.elementAt(identity); - if (dataIndex > 0) + if (dataIndex >= 0) { return m_chars.getString(dataIndex >>> TEXT_LENGTH_BITS, dataIndex & TEXT_LENGTH_MAX); @@ -2977,7 +2978,7 @@ if ((_exptype2(child) == DTM.TEXT_NODE) && (_nextsib2(child) == DTM.NULL)) { int dataIndex = m_dataOrQName.elementAt(child); - if (dataIndex > 0) + if (dataIndex >= 0) return m_chars.getString(dataIndex >>> TEXT_LENGTH_BITS, dataIndex & TEXT_LENGTH_MAX); else return m_chars.getString(m_data.elementAt(-dataIndex), @@ -3036,7 +3037,7 @@ { int dataIndex = m_dataOrQName.elementAt(identity); - if (dataIndex > 0) + if (dataIndex >= 0) { if (-1 == offset) { @@ -3072,7 +3073,7 @@ { int dataIndex = m_dataOrQName.elementAt(identity); - if (dataIndex > 0) + if (dataIndex >= 0) { if (normalize) m_chars.sendNormalizedSAXcharacters(ch, dataIndex >>> TEXT_LENGTH_BITS, @@ -3167,7 +3168,7 @@ { if (nodeID != DTM.NULL) { int dataIndex = m_dataOrQName.elementAt(nodeID); - if (dataIndex > 0) { + if (dataIndex >= 0) { m_chars.sendSAXcharacters(handler, dataIndex >>> TEXT_LENGTH_BITS, dataIndex & TEXT_LENGTH_MAX); --------------------------------------------------------------------- To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org For additional commands, e-mail: xalan-cvs-help@xml.apache.org