Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zulutosec cannot convert correctly #538

Closed
s1r-J opened this issue Feb 8, 2022 · 1 comment
Closed

zulutosec cannot convert correctly #538

s1r-J opened this issue Feb 8, 2022 · 1 comment

Comments

@s1r-J
Copy link

s1r-J commented Feb 8, 2022

  • version: 10.5.1

zulutosec cannot convert some future times(e.g. '401231235959Z') correctly.

zulutosec uses ~ for cutting off after the decimal point.
Bitwise not (~ ) converts integer with more than 32 bits into a 32-bit signed integer.
So, '401231235959Z'(Unix time is 2240611199000, more than 32 bits) will be shotened by bitwise not operator and be coverted incorrectly.

Bitwise NOT (~) - JavaScript | MDN

Sample code is following.

const overflowDateStr = '401231235959Z'; // 2040 Dec 31 23:59:59
const overflowDate = new Date(Date.UTC(2000 + parseInt(overflowDateStr.slice(0, 2)), parseInt(overflowDateStr.slice(2, 4)) - 1, parseInt(overflowDateStr.slice(4, 6)), parseInt(overflowDateStr.slice(6, 8)), parseInt(overflowDateStr.slice(8, 10)), parseInt(overflowDateStr.slice(10, 12))))
console.log(overflowDate.getTime());                 // 2240611199000
console.log(jsrsasign.zulutomsec(overflowDateStr));  // 2240611199000
console.log(jsrsasign.zulutosec(overflowDateStr));   // -2054356097

console.log(Math.floor(jsrsasign.zulutomsec(overflowDateStr)/1000));  // 2240611199

Thanks.

@kjur
Copy link
Owner

kjur commented Mar 9, 2022

Thank you for your report. It will be fixed in the release today.

@kjur kjur closed this as completed Mar 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants