0014-Handle-negative-xsl-number-values.patch 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. From 69ec3da1b653024aca6515ddd4adc91919dd188e Mon Sep 17 00:00:00 2001
  2. From: Nick Wellnhofer <wellnhofer@aevum.de>
  3. Date: Sun, 10 Apr 2016 12:51:57 +0200
  4. Subject: [PATCH] Handle negative xsl:number values
  5. According to XSLT 2.0, negative values are a non-recoverable dynamic error.
  6. Print an error message and treat negative values as zero.
  7. Fixes an OOB array access in xsltNumberFormatAlpha.
  8. ---
  9. libxslt/numbers.c | 17 ++++++++++++++++-
  10. 1 file changed, 16 insertions(+), 1 deletion(-)
  11. diff --git a/libxslt/numbers.c b/libxslt/numbers.c
  12. index eb087bc..a3cabcf 100644
  13. --- a/libxslt/numbers.c
  14. +++ b/libxslt/numbers.c
  15. @@ -246,7 +246,7 @@ xsltNumberFormatAlpha(xmlBufferPtr buffer,
  16. number--;
  17. *(--pointer) = alpha_list[((int)fmod(number, alpha_size))];
  18. number /= alpha_size;
  19. - if (fabs(number) < 1.0)
  20. + if (number < 1.0)
  21. break; /* for */
  22. }
  23. xmlBufferCCat(buffer, pointer);
  24. @@ -442,6 +442,21 @@ xsltNumberFormatInsertNumbers(xsltNumberDataPtr data,
  25. number = numbers[(numbers_max - 1) - i];
  26. /* Round to nearest like XSLT 2.0 */
  27. number = floor(number + 0.5);
  28. + /*
  29. + * XSLT 1.0 isn't clear on how to handle negative numbers, but XSLT
  30. + * 2.0 says:
  31. + *
  32. + * It is a non-recoverable dynamic error if any undiscarded item
  33. + * in the atomized sequence supplied as the value of the value
  34. + * attribute of xsl:number cannot be converted to an integer, or
  35. + * if the resulting integer is less than 0 (zero).
  36. + */
  37. + if (number < 0.0) {
  38. + xsltTransformError(NULL, NULL, NULL,
  39. + "xsl-number : negative value\n");
  40. + /* Recover by treating negative values as zero. */
  41. + number = 0.0;
  42. + }
  43. if (i < tokens->nTokens) {
  44. /*
  45. * The "n"th format token will be used to format the "n"th
  46. --
  47. 2.8.1