Skip to content

MsgPackLite broken pack for ulongs higher than Long.MAX_VALUE #27

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

Closed
isopov opened this issue Jun 15, 2017 · 0 comments
Closed

MsgPackLite broken pack for ulongs higher than Long.MAX_VALUE #27

isopov opened this issue Jun 15, 2017 · 0 comments

Comments

@isopov
Copy link

isopov commented Jun 15, 2017

It is possible to unpack ulong bigger than Long.MAX_VALUE correctly as BigInteger. But it is not possible to pack it correctly - it becomes unsigned.

	public static void main(String[] args) throws IOException {
		byte[] pack = bytesInQuestion();
		// correct unpacking
		BigInteger unpackValue = (BigInteger) MsgPackLite.INSTANCE.unpack(new ByteArrayInputStream(pack));
		// let's pack it back again
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		MsgPackLite.INSTANCE.pack(unpackValue, out);
		byte[] repack = out.toByteArray();

		System.out.println(Arrays.equals(pack, repack));
		System.out.println(Arrays.toString(pack));
		System.out.println(Arrays.toString(repack));
		//false
		//[-49, -128, 0, 0, 0, 127, -1, -1, -2]
		//[-50, 127, -1, -1, -2]
	}

	private static byte[] bytesInQuestion() throws IOException {
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		DataOutputStream dataStream = new DataOutputStream(out);
		try {
			dataStream.write(MsgPackLite.INSTANCE.MP_UINT64);
			dataStream.writeLong(Long.MAX_VALUE + Integer.MAX_VALUE);
			return out.toByteArray();
		} finally {
			dataStream.close();
		}
	}
@isopov isopov changed the title MsgPackLite broken pack for ulongs MsgPackLite broken pack for ulongs higher than Long.MAX_VALUE Jun 15, 2017
Totktonada added a commit that referenced this issue Jan 23, 2019
Totktonada added a commit that referenced this issue Jan 28, 2019
Totktonada added a commit that referenced this issue Jan 28, 2019
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

1 participant