drmohundro / SWXMLHash

Simple XML parsing in Swift
MIT License
1.41k stars 205 forks source link

Crash due to incorrect element count validation #155

Closed badscientist-zz closed 7 years ago

badscientist-zz commented 7 years ago

Line: 679: if index <= list.count {

Using <= in this condition is causing a crash when the user attempts to select a non-existent value that exceeds list.count. This is happening because list.count does not factor in that array indexes begin at zero.

Example, if list.count returns 5 and the user is requesting the value with an index key of 5, this condition (line 679) will succeed but, because the fifth value in list has an index key of 4, line 680: return .element(list[index]) will fail and cause a crash.

I made the following simple change and it fixed this crash:

Line: 679: if index < list.count {

Oh, and thanks for project btw!

drmohundro commented 7 years ago

@badscientist wow, I can't believe this one hadn't been reported yet! Also, there was clearly a gap in my testing. I've added a PR for this - once the build server gives me the green light, I'll merge and release a bug fix.

Thanks for the report!

drmohundro commented 7 years ago

I just published 4.2.3 for this. Thanks again for the report!