File tree 1 file changed +15
-7
lines changed
1 file changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -213,15 +213,23 @@ func parsePAXTime(s string) (time.Time, error) {
213
213
}
214
214
215
215
// Parse the nanoseconds.
216
- if strings .Trim (sn , "0123456789" ) != "" {
217
- return time.Time {}, ErrHeader
216
+ nanoDigits := [maxNanoSecondDigits ]byte {}
217
+ i := 0
218
+ for _ , c := range sn {
219
+ if c < '0' || c > '9' {
220
+ return time.Time {}, ErrHeader
221
+ }
222
+ // Right truncate
223
+ if i < maxNanoSecondDigits {
224
+ nanoDigits [i ] = byte (c )
225
+ i ++
226
+ }
218
227
}
219
- if len (sn ) < maxNanoSecondDigits {
220
- sn += strings .Repeat ("0" , maxNanoSecondDigits - len (sn )) // Right pad
221
- } else {
222
- sn = sn [:maxNanoSecondDigits ] // Right truncate
228
+ // Right pad
229
+ for ; i < maxNanoSecondDigits ; i ++ {
230
+ nanoDigits [i ] = '0'
223
231
}
224
- nsecs , _ := strconv .ParseInt (sn , 10 , 64 ) // Must succeed
232
+ nsecs , _ := strconv .ParseInt (string ( nanoDigits [:]) , 10 , 64 ) // Must succeed after validation
225
233
if len (ss ) > 0 && ss [0 ] == '-' {
226
234
return time .Unix (secs , - 1 * nsecs ), nil // Negative correction
227
235
}
You can’t perform that action at this time.
0 commit comments