Commit aba138c
committed
Fix out-of-bounds access possibility in safe code.
With the `id` and `tree` fields of `NodeRef` and `NodeMut` being public,
it was possible to assign to them.
For example, it was possible to build a `NodeMut`
for large ID/index in a small tree/Vec.
Since some APIs use unchecked indexing, this would let users of this library
cause out-of-bounds access in a `Vec` without writing `unsafe` code themselves.
This commit fixes that issue by making the fields private
and instead providing read-only access via accessor methods.
Now the fields can only be set by the `ego-tree` crate,
which can make sure to only ever use an ID that is in-bounds for a given tree.1 parent 3efaff6 commit aba138c
2 files changed
+5
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
80 | | - | |
| 79 | + | |
81 | 80 | | |
82 | 81 | | |
83 | | - | |
84 | | - | |
| 82 | + | |
85 | 83 | | |
86 | 84 | | |
87 | 85 | | |
| |||
90 | 88 | | |
91 | 89 | | |
92 | 90 | | |
93 | | - | |
94 | | - | |
| 91 | + | |
95 | 92 | | |
96 | 93 | | |
97 | | - | |
98 | | - | |
| 94 | + | |
99 | 95 | | |
100 | 96 | | |
101 | 97 | | |
| |||
107 | 103 | | |
108 | 104 | | |
109 | 105 | | |
110 | | - | |
111 | 106 | | |
112 | 107 | | |
113 | 108 | | |
114 | 109 | | |
115 | 110 | | |
116 | 111 | | |
117 | 112 | | |
118 | | - | |
119 | 113 | | |
120 | 114 | | |
121 | 115 | | |
| |||
176 | 170 | | |
177 | 171 | | |
178 | 172 | | |
179 | | - | |
180 | 173 | | |
181 | 174 | | |
182 | 175 | | |
| |||
229 | 222 | | |
230 | 223 | | |
231 | 224 | | |
232 | | - | |
233 | 225 | | |
234 | 226 | | |
235 | 227 | | |
| |||
548 | 540 | | |
549 | 541 | | |
550 | 542 | | |
551 | | - | |
552 | 543 | | |
553 | 544 | | |
554 | 545 | | |
| |||
0 commit comments