Skip to content

Commit 1c8409e

Browse files
committed
out of range panic fix
1 parent a42f0e2 commit 1c8409e

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

unicode/norm/forminfo.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,18 @@ func compInfo(v uint16, sz int) Properties {
256256
return p
257257
}
258258
// has decomposition
259-
h := decomps[v]
259+
h, ok := decompsVal(v)
260+
if !ok {
261+
return Properties{size: uint8(sz)}
262+
}
260263
f := (qcInfo(h&headerFlagsMask) >> 2) | 0x4
261264
p := Properties{size: uint8(sz), flags: f, index: v}
262265
if v >= firstCCC {
263266
v += uint16(h&headerLenMask) + 1
264-
c := decomps[v]
267+
c, ok := decompsVal(v)
268+
if !ok {
269+
return Properties{size: uint8(sz)}
270+
}
265271
p.tccc = c >> 2
266272
p.flags |= qcInfo(c & 0x3)
267273
if v >= firstLeadingCCC {
@@ -272,8 +278,19 @@ func compInfo(v uint16, sz int) Properties {
272278
p.index = 0
273279
return p
274280
}
275-
p.ccc = decomps[v+1]
281+
ccc, ok := decompsVal(v + 1)
282+
if !ok {
283+
return Properties{size: uint8(sz)}
284+
}
285+
p.ccc = ccc
276286
}
277287
}
278288
return p
279289
}
290+
291+
func decompsVal(v uint16) (byte, bool) {
292+
if int(v) >= len(decomps) {
293+
return 0, false
294+
}
295+
return decomps[v], true
296+
}

0 commit comments

Comments
 (0)