summaryrefslogtreecommitdiffstats
path: root/academic/root/fixWriteFastArray.patch
blob: 91d0b2f7691c4f65b3b280a40154402b983c5b00 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
From 9f847714d9dbb432d9e6ce27954711e3819ddfee Mon Sep 17 00:00:00 2001
From: Mattias Ellert <mattias.ellert@physics.uu.se>
Date: Fri, 7 Jun 2024 06:49:39 +0200
Subject: [PATCH 1/2] [io] WriteFastArray: return early if n == 0, to prevent
 crash in bswapcpy

---
 io/io/src/TBufferFile.cxx | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/io/io/src/TBufferFile.cxx b/io/io/src/TBufferFile.cxx
index 81e0f95e02..b5b7ef9831 100644
--- a/io/io/src/TBufferFile.cxx
+++ b/io/io/src/TBufferFile.cxx
@@ -1948,6 +1948,8 @@ void TBufferFile::WriteArrayDouble32(const Double_t *d, Int_t n, TStreamerElemen

 void TBufferFile::WriteFastArray(const Bool_t *b, Long64_t n)
 {
+   if (n == 0) return;
+
    constexpr Int_t dataWidth = static_cast<Int_t>(sizeof(UChar_t));
    const Int_t maxElements = (std::numeric_limits<Int_t>::max() - Length())/dataWidth;
    if (n < 0 || n > maxElements)
@@ -1974,6 +1976,8 @@ void TBufferFile::WriteFastArray(const Bool_t *b, Long64_t n)

 void TBufferFile::WriteFastArray(const Char_t *c, Long64_t n)
 {
+   if (n == 0) return;
+
    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)
@@ -1995,6 +1999,8 @@ void TBufferFile::WriteFastArray(const Char_t *c, Long64_t n)

 void TBufferFile::WriteFastArrayString(const Char_t *c, Long64_t n)
 {
+   if (n == 0) return;
+
    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)
@@ -2023,6 +2029,8 @@ void TBufferFile::WriteFastArrayString(const Char_t *c, Long64_t n)

 void TBufferFile::WriteFastArray(const Short_t *h, Long64_t n)
 {
+   if (n == 0) return;
+
    constexpr Int_t dataWidth = static_cast<Int_t>(sizeof(Short_t));
    const Int_t maxElements = (std::numeric_limits<Int_t>::max() - Length())/dataWidth;
    if (n < 0 || n > maxElements)
@@ -2054,7 +2062,8 @@ void TBufferFile::WriteFastArray(const Short_t *h, Long64_t n)

 void TBufferFile::WriteFastArray(const Int_t *ii, Long64_t n)
 {
-   
+   if (n == 0) return;
+
    constexpr Int_t dataWidth = 4;
    const Int_t maxElements = (std::numeric_limits<Int_t>::max() - Length())/dataWidth;
    if (n < 0 || n > maxElements)
@@ -2086,6 +2095,8 @@ void TBufferFile::WriteFastArray(const Int_t *ii, Long64_t n)

 void TBufferFile::WriteFastArray(const Long_t *ll, Long64_t n)
 {
+   if (n == 0) return;
+
    constexpr Int_t dataWidth = 8;
    const Int_t maxElements = (std::numeric_limits<Int_t>::max() - Length())/dataWidth;
    if (n < 0 || n > maxElements)
@@ -2108,6 +2119,8 @@ void TBufferFile::WriteFastArray(const Long_t *ll, Long64_t n)

 void TBufferFile::WriteFastArray(const ULong_t *ll, Long64_t n)
 {
+   if (n == 0) return;
+
    constexpr Int_t dataWidth = 8;
    const Int_t maxElements = (std::numeric_limits<Int_t>::max() - Length())/dataWidth;
    if (n < 0 || n > maxElements)
@@ -2128,6 +2141,8 @@ void TBufferFile::WriteFastArray(const ULong_t *ll, Long64_t n)

 void TBufferFile::WriteFastArray(const Long64_t *ll, Long64_t n)
 {
+   if (n == 0) return;
+
    constexpr Int_t dataWidth = static_cast<Int_t>(sizeof(Long64_t));
    const Int_t maxElements = (std::numeric_limits<Int_t>::max() - Length())/dataWidth;
    if (n < 0 || n > maxElements)
@@ -2154,6 +2169,8 @@ void TBufferFile::WriteFastArray(const Long64_t *ll, Long64_t n)

 void TBufferFile::WriteFastArray(const Float_t *f, Long64_t n)
 {
+   if (n == 0) return;
+
    constexpr Int_t dataWidth = static_cast<Int_t>(sizeof(Float_t));
    const Int_t maxElements = (std::numeric_limits<Int_t>::max() - Length())/dataWidth;
    if (n < 0 || n > maxElements)
@@ -2185,6 +2202,8 @@ void TBufferFile::WriteFastArray(const Float_t *f, Long64_t n)

 void TBufferFile::WriteFastArray(const Double_t *d, Long64_t n)
 {
+   if (n == 0) return;
+
    constexpr Int_t dataWidth = static_cast<Int_t>(sizeof(Double_t));
    const Int_t maxElements = (std::numeric_limits<Int_t>::max() - Length())/dataWidth;
    if (n < 0 || n > maxElements)
@@ -2212,6 +2231,8 @@ void TBufferFile::WriteFastArray(const Double_t *d, Long64_t n)

 void TBufferFile::WriteFastArrayFloat16(const Float_t *f, Long64_t n, TStreamerElement *ele)
 {
+   if (n == 0) return;
+
    constexpr Int_t dataWidth = static_cast<Int_t>(sizeof(Float_t));
    const Int_t maxElements = (std::numeric_limits<Int_t>::max() - Length())/dataWidth;
    if (n < 0 || n > maxElements)
@@ -2270,6 +2291,8 @@ void TBufferFile::WriteFastArrayFloat16(const Float_t *f, Long64_t n, TStreamerE

 void TBufferFile::WriteFastArrayDouble32(const Double_t *d, Long64_t n, TStreamerElement *ele)
 {
+   if (n == 0) return;
+
    constexpr Int_t dataWidth = static_cast<Int_t>(sizeof(Float_t));
    const Int_t maxElements = (std::numeric_limits<Int_t>::max() - Length())/dataWidth;
    if (n < 0 || n > maxElements)
--
2.39.4