0015-Lower-bound-for-format-token-a.patch 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. From 405034286fbdd6166229335b7203a41bf53b40fc Mon Sep 17 00:00:00 2001
  2. From: Nick Wellnhofer <wellnhofer@aevum.de>
  3. Date: Sun, 10 Apr 2016 13:11:31 +0200
  4. Subject: [PATCH] Lower bound for format token "a"
  5. Handle xsl:number with format "a" and value 0 according to XSLT 2.0.
  6. Fixes an OOB array access in xsltNumberFormatAlpha.
  7. ---
  8. libxslt/numbers.c | 33 ++++++++++++++++++++++++---------
  9. 1 file changed, 24 insertions(+), 9 deletions(-)
  10. diff --git a/libxslt/numbers.c b/libxslt/numbers.c
  11. index a3cabcf..af52883 100644
  12. --- a/libxslt/numbers.c
  13. +++ b/libxslt/numbers.c
  14. @@ -227,7 +227,8 @@ xsltNumberFormatDecimal(xmlBufferPtr buffer,
  15. }
  16. static void
  17. -xsltNumberFormatAlpha(xmlBufferPtr buffer,
  18. +xsltNumberFormatAlpha(xsltNumberDataPtr data,
  19. + xmlBufferPtr buffer,
  20. double number,
  21. int is_upper)
  22. {
  23. @@ -237,6 +238,26 @@ xsltNumberFormatAlpha(xmlBufferPtr buffer,
  24. char *alpha_list;
  25. double alpha_size = (double)(sizeof(alpha_upper_list) - 1);
  26. + /*
  27. + * XSLT 1.0 isn't clear on how to handle zero, but XSLT 2.0 says:
  28. + *
  29. + * For all format tokens other than the first kind above (one that
  30. + * consists of decimal digits), there may be implementation-defined
  31. + * lower and upper bounds on the range of numbers that can be
  32. + * formatted using this format token; indeed, for some numbering
  33. + * sequences there may be intrinsic limits. [...] Numbers that fall
  34. + * outside this range must be formatted using the format token 1.
  35. + *
  36. + * The "a" token has an intrinsic lower limit of 1.
  37. + */
  38. + if (number < 1.0) {
  39. + xsltNumberFormatDecimal(buffer, number, '0', 1,
  40. + data->digitsPerGroup,
  41. + data->groupingCharacter,
  42. + data->groupingCharacterLen);
  43. + return;
  44. + }
  45. +
  46. /* Build buffer from back */
  47. pointer = &temp_string[sizeof(temp_string)];
  48. *(--pointer) = 0;
  49. @@ -500,16 +521,10 @@ xsltNumberFormatInsertNumbers(xsltNumberDataPtr data,
  50. switch (token->token) {
  51. case 'A':
  52. - xsltNumberFormatAlpha(buffer,
  53. - number,
  54. - TRUE);
  55. -
  56. + xsltNumberFormatAlpha(data, buffer, number, TRUE);
  57. break;
  58. case 'a':
  59. - xsltNumberFormatAlpha(buffer,
  60. - number,
  61. - FALSE);
  62. -
  63. + xsltNumberFormatAlpha(data, buffer, number, FALSE);
  64. break;
  65. case 'I':
  66. xsltNumberFormatRoman(buffer,
  67. --
  68. 2.8.1