tstring-support.patch 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. commit 95c5a57badd5a8cddce3fae7be593d1de3e1f9f7 (HEAD -> snappy-std)
  2. author: thegeorg
  3. date: 2021-08-03T16:56:11+03:00
  4. Restore partial TString support
  5. --- a/snappy.cc
  6. +++ b/snappy.cc
  7. @@ -73,6 +73,7 @@
  8. #include <string>
  9. #include <utility>
  10. #include <vector>
  11. +#include <util/generic/string.h>
  12. namespace snappy {
  13. @@ -1847,6 +1847,20 @@ bool Uncompress(const char* compressed, size_t n, std::string* uncompressed) {
  14. string_as_array(uncompressed));
  15. }
  16. +bool Uncompress(const char* compressed, size_t n, TString* uncompressed) {
  17. + size_t ulength;
  18. + if (!GetUncompressedLength(compressed, n, &ulength)) {
  19. + return false;
  20. + }
  21. + // On 32-bit builds: max_size() < kuint32max. Check for that instead
  22. + // of crashing (e.g., consider externally specified compressed data).
  23. + if (ulength > uncompressed->max_size()) {
  24. + return false;
  25. + }
  26. + uncompressed->ReserveAndResize(ulength);
  27. + return RawUncompress(compressed, n, uncompressed->begin());
  28. +}
  29. +
  30. // A Writer that drops everything on the floor and just does validation
  31. class SnappyDecompressionValidator {
  32. private:
  33. @@ -1901,6 +1901,16 @@ size_t Compress(const char* input, size_t input_length,
  34. return compressed_length;
  35. }
  36. +size_t Compress(const char* input, size_t input_length, TString* compressed) {
  37. + // Pre-grow the buffer to the max length of the compressed output
  38. + compressed->ReserveAndResize(MaxCompressedLength(input_length));
  39. +
  40. + size_t compressed_length;
  41. + RawCompress(input, input_length, compressed->begin(), &compressed_length);
  42. + compressed->resize(compressed_length);
  43. + return compressed_length;
  44. +}
  45. +
  46. // -----------------------------------------------------------------------
  47. // Sink interface
  48. // -----------------------------------------------------------------------
  49. --- a/snappy.h
  50. +++ b/snappy.h
  51. @@ -42,6 +42,7 @@
  52. #include <stdint.h>
  53. #include <string>
  54. +#include <util/generic/fwd.h>
  55. #include "snappy-stubs-public.h"
  56. @@ -75,4 +77,6 @@ namespace snappy {
  57. size_t Compress(const char* input, size_t input_length,
  58. std::string* compressed);
  59. + size_t Compress(const char* input, size_t input_length,
  60. + TString* compressed);
  61. size_t Compress(const char* input, size_t input_length,
  62. std::string* compressed, CompressionOptions options);
  63. @@ -84,6 +88,8 @@ namespace snappy {
  64. // returns false if the message is corrupted and could not be decompressed
  65. bool Uncompress(const char* compressed, size_t compressed_length,
  66. std::string* uncompressed);
  67. + bool Uncompress(const char* compressed, size_t compressed_length,
  68. + TString* uncompressed);
  69. // Decompresses "compressed" to "*uncompressed".
  70. //