root/root-Fix-writing-long-strings.patch
Mattias Ellert 03696fac62 Update to 6.30.08
Fixes for TUri class (PCRE2 compatibility)
Update ROOT's R interface for Rcpp 1.0.13
2024-07-23 01:46:15 +02:00

68 lines
2 KiB
Diff

From 638593e77b76895db85470a3303d5fe0366e8ec4 Mon Sep 17 00:00:00 2001
From: scott snyder <snyder@bnl.gov>
Date: Wed, 6 Mar 2024 04:06:50 +0100
Subject: [PATCH] Fix writing long strings.
In TBufferFile::WriteFastArrayString, we had
```
if (n < 255) {
*this << (UChar_t)n;
} else {
*this << (UChar_t)255;
*this << n;
}
```
A recent commit changed the type of the n parameter from Int_t to Long64_t.
This is effectively an incompatible change in the on-disk format, but only for strings
which are at least 255 characters long.
Further, ReadFastArrayString is still reading an Int_t, so this version of ROOT cannot
read files that it writes.
Resolve by changing WriteFastArrayString to explicitly write an Int_t.
Also move the bounds check on the length to before writing anything into the buffer.
Fixes a failure seen in the unit tests of the ATLAS EventInfo package
in the dev3LCG build.
---
io/io/src/TBufferFile.cxx | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/io/io/src/TBufferFile.cxx b/io/io/src/TBufferFile.cxx
index 7b1fe370bb..81e0f95e02 100644
--- a/io/io/src/TBufferFile.cxx
+++ b/io/io/src/TBufferFile.cxx
@@ -1995,13 +1995,6 @@ void TBufferFile::WriteFastArray(const Char_t *c, Long64_t n)
void TBufferFile::WriteFastArrayString(const Char_t *c, Long64_t n)
{
- if (n < 255) {
- *this << (UChar_t)n;
- } else {
- *this << (UChar_t)255;
- *this << n;
- }
-
constexpr Int_t dataWidth = static_cast<Int_t>(sizeof(Char_t));
const Int_t maxElements = (std::numeric_limits<Int_t>::max() - Length())/dataWidth;
if (n < 0 || n > maxElements)
@@ -2010,6 +2003,13 @@ void TBufferFile::WriteFastArrayString(const Char_t *c, Long64_t n)
return; // In case the user re-routes the error handler to not die when Fatal is called
}
+ if (n < 255) {
+ *this << (UChar_t)n;
+ } else {
+ *this << (UChar_t)255;
+ *this << (Int_t)n;
+ }
+
Int_t l = sizeof(Char_t)*n;
if (fBufCur + l > fBufMax) AutoExpand(fBufSize+l);
--
2.45.2