Commit 6a999af
committed
Address PR #1602 review: validate band upstream in _vrt.read_vrt
- Move the ``band`` range/type check into the internal ``_vrt.read_vrt``
reader where ``len(vrt.bands)`` is already in scope. Reject negative
indices, non-int values, and out-of-range positive values with a
clear ``ValueError`` that names the available band count. Previously
these would either silently return a different band (Python negative
indexing), raise an opaque ``IndexError`` deep in the read path, or
raise ``TypeError`` on the list index.
- Drop the now-redundant post-parse guard in the public ``read_vrt``
and update the comment to reflect that ``band`` is validated upstream.
- Add three regression tests covering the negative, out-of-range, and
non-int rejection paths.
The original bug from #1598 (band=N reads pairing with band 0's nodata
sentinel) was masked by these silent acceptances on the negative-band
edge: ``read_vrt(path, band=-1)`` previously returned the last band's
data with ``attrs['nodata']`` unset entirely.1 parent 008fcb1 commit 6a999af
3 files changed
Lines changed: 56 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2738 | 2738 | | |
2739 | 2739 | | |
2740 | 2740 | | |
| 2741 | + | |
| 2742 | + | |
2741 | 2743 | | |
2742 | 2744 | | |
2743 | 2745 | | |
2744 | | - | |
2745 | | - | |
2746 | | - | |
2747 | | - | |
2748 | | - | |
2749 | | - | |
2750 | | - | |
| 2746 | + | |
| 2747 | + | |
| 2748 | + | |
2751 | 2749 | | |
2752 | 2750 | | |
2753 | 2751 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
245 | 262 | | |
246 | 263 | | |
247 | 264 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
105 | 106 | | |
106 | 107 | | |
107 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
0 commit comments