Subject: [xml2rfc] #327 (Version 2 cli): Having more than 26 appendices causes unhandled exception

From: "xml2rfc issue tracker" <[email-masked]>
Date: Mon, 12 Sep 2016 23:55:32 -0000

#327: Having more than 26 appendices causes unhandled exception

 When an xml2rfc source has more than 26 appendices, an unhanded exception
 occurs.

 To verify this behavior, create an xml2rfc document with more than 26
 appendices, such as:

 <back>
  <references>...</references>
  <section title="test"><t>test</t></section>
  (repeated 26 or more times)
 </back>

 Then run it on xml2rfc.

 Exemplary output:

 Traceback (most recent call last):
   File "/usr/local/bin/xml2rfc", line 5, in <module>
     pkg_resources.run_script('xml2rfc==2.4.8w', 'xml2rfc')
   File
 "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py",
 line 492, in run_script
     self.require(requires)[0].run_script(script_name, ns)
   File
 "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py",
 line 1350, in run_script
     execfile(script_filename, namespace, namespace)
   File ".../EGG-INFO/scripts/xml2rfc", line 225, in <module>
     main()
   File ".../EGG-INFO/scripts/xml2rfc", line 192, in main
     htmlwriter.write(filename)
   File ".../xml2rfc/writers/base.py", line 1186, in write
     self._build_index()
   File ".../xml2rfc/writers/base.py", line 1035, in _build_index
     self.write_section_rec(back, None, appendix=True)
   File ".../xml2rfc/writers/base.py", line 865, in write_section_rec
     self.write_section_rec(child_sec, uppercase[s_count - 1],
 IndexError: string index out of range

 (Note that, at present, there is no limitation on the number of appendices
 in the xml2rfc vocabulary.)

 The underlying problem is that the code around lines 863-866 in base.py
 have undefined behavior past 26:

                 # Use an alphabetic counter for first-level appendix
                 uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                 self.write_section_rec(child_sec, uppercase[s_count - 1],
                                         level=level + 1, appendix=True)

 One correct solution is to compute the appendix letter(s) by converting to
 base 26 ( mod 26 and divide by 26) to get AA-AZ, BA-BZ, etc. as discussed
 in Stack Overflow question #15791780.

-- 
-------------------------------------------+-------------------------------
 Reporter:  [email-masked]           |      Owner:
     Type:  defect                         |  [email-masked]
 Priority:  medium                         |     Status:  new
Component:  Version 2 cli                  |  Milestone:
 Keywords:  appendix, appendices, section  |    Version:  2.5.x
-------------------------------------------+-------------------------------

Ticket URL: <https://trac.tools.ietf.org/tools/xml2rfc/trac/ticket/327>
xml2rfc <http://tools.ietf.org/tools/xml2rfc/>

---

From: "xml2rfc issue tracker" <[email-masked]>
Date: Tue, 13 Sep 2016 03:34:20 -0000

Changes (by [email-masked]):

 * status:  new => closed
 * resolution:   => fixed

Comment:

 Fixed in [2253]:

 fix for #327

-- 
-------------------------------+-------------------------------------------
  Reporter:                    |      Owner:  [email-masked]
  [email-masked]         |     Status:  closed
      Type:  defect            |  Milestone:
  Priority:  medium            |    Version:  2.5.x
 Component:  Version 2 cli     |   Keywords:  appendix, appendices, section
Resolution:  fixed             |
-------------------------------+-------------------------------------------

Ticket URL: </ticket/327#comment:1>
xml2rfc <http://tools.ietf.org/tools/xml2rfc/>

---

From: "xml2rfc issue tracker" <[email-masked]>
Date: Tue, 13 Sep 2016 19:40:02 -0000

Comment (by [email-masked]):

 I tested the patch and it addresses this bug. Thank you!

Ticket URL: <https://trac.tools.ietf.org/tools/xml2rfc/trac/ticket/327#comment:2>
xml2rfc <http://tools.ietf.org/tools/xml2rfc/>