Package: libwbxml2
Version: 0.9.0-3
Severity: important
Tags: patch

When encoding DRM REL document from XML to WBXML, the ds:KeyValue 
element is not encoded properly. When the ds:KeyValue element is 
represented in base64 encoding in the XML document, it needs to be
base64-decoded before storing the value as opaque data in the WBXML
output, but instead it gets put as-is into the WBXML document!

The 'wbxml_encode_drmrel_content' function in wbxml_encoder.c is
supposed to take care of this decoding, but it does not do so. The
reason seems to be that the following test (line 2655) is always
false (the current 'tag' is a text value):

   if (encoder->current_tag != NULL)

To determine whether we are in a ds:KeyValue, we need to look at the
parent of the current node, which is what the attached patch does.

I suspect that Wireless Village encoding is also broken as it also
relies on encoder->current_tag.

Cheers,
Jeremy

-- System Information:
Debian Release: testing/unstable
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'testing'), (500, 'stable')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.12
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)

Versions of packages libwbxml2 depends on:
ii  libc6                         2.3.5-8    GNU C Library: Shared libraries an
ii  libexpat1                     1.95.8-3   XML parsing C library - runtime li
ii  libpopt0                      1.7-5      lib for parsing cmdline parameters
ii  zlib1g                        1:1.2.3-8  compression library - runtime

libwbxml2 recommends no packages.

-- no debconf information
diff -urN wbxml2-0.9.0.orig/src/wbxml_encoder.c wbxml2-0.9.0/src/wbxml_encoder.c
--- wbxml2-0.9.0.orig/src/wbxml_encoder.c       2005-11-30 22:48:18.000000000 
+0100
+++ wbxml2-0.9.0/src/wbxml_encoder.c    2005-11-30 22:47:55.000000000 +0100
@@ -98,6 +98,7 @@
     WBXMLTree *tree;                        /**< WBXML Tree to Encode */
     WBXMLBuffer *output;                    /**< The output (wbxml or xml) we 
are producing */
     const WBXMLTagEntry *current_tag;       /**< Current Tag (See The Warning 
For This Field !) */
+    const WBXMLTreeNode *current_text_parent; /**< Parent of the current Node 
(Used for DRM REL) */
     const WBXMLAttrEntry *current_attr;     /**< Current Attribute */
     WB_UTINY tagCodePage;                   /**< Current Tag Code Page */
     WB_UTINY attrCodePage;                  /**< Current Attribute Code Page */
@@ -335,6 +336,7 @@
     encoder->output = NULL;
 
     encoder->current_tag = NULL;
+    encoder->current_text_parent = NULL;
     encoder->current_attr = NULL;
 
     encoder->tagCodePage = 0;
@@ -831,6 +833,8 @@
  */
 static WBXMLError parse_text(WBXMLEncoder *encoder, WBXMLTreeNode *node)
 {
+    WBXMLError ret;
+
        /* Do not modify text inside a CDATA section */
        if (!encoder->in_cdata) {
     /* If Canonical Form: "Ignorable white space is considered significant and 
is treated equivalently to data" */
@@ -877,7 +881,10 @@
         }
         else {
                /* Encode text */
-        return wbxml_encode_value_element_buffer(encoder, 
wbxml_buffer_get_cstr(node->content), WBXML_VALUE_ELEMENT_CTX_CONTENT);
+        encoder->current_text_parent = node->parent;
+        ret = wbxml_encode_value_element_buffer(encoder, 
wbxml_buffer_get_cstr(node->content), WBXML_VALUE_ELEMENT_CTX_CONTENT);
+        encoder->current_text_parent = NULL;
+        return ret;
         }
     case WBXML_ENCODER_OUTPUT_XML:
         return xml_encode_text(encoder, node->content);
@@ -2650,11 +2657,19 @@
 {
     WB_UTINY *data = NULL;
     WB_LONG data_len = 0;
+    WBXMLTagEntry *current_tag = NULL;
 
-    if (encoder->current_tag != NULL) 
+    if ((encoder->current_text_parent != NULL) && 
+        (encoder->current_text_parent->name != NULL) &&
+        (encoder->current_text_parent->name->type == WBXML_VALUE_TOKEN))
+    {
+        current_tag = encoder->current_text_parent->name->u.token;
+    }
+
+    if (current_tag != NULL) 
     {
-        if ((encoder->current_tag->wbxmlCodePage == 0x00) &&
-            (encoder->current_tag->wbxmlToken == 0x0C))
+        if ((current_tag->wbxmlCodePage == 0x00) &&
+            (current_tag->wbxmlToken == 0x0C))
         {
             /* <ds:KeyValue> content: "Encoded in binary format, i.e., no 
base64 encoding" */
 

Reply via email to