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

typia.protobuf.decode ignored byteOffset and byteLength #912

Closed
ghlin opened this issue Dec 28, 2023 · 2 comments
Closed

typia.protobuf.decode ignored byteOffset and byteLength #912

ghlin opened this issue Dec 28, 2023 · 2 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request good first issue Good for newcomers

Comments

@ghlin
Copy link
Contributor

ghlin commented Dec 28, 2023

Calling typia.protobuf.decode (or typia.protobuf.createDecode) with Buffer throws 'buffer overflow'.

minimal code to reproduce:

import typia from 'typia'

type Foo = {
  id: number & typia.tags.Type<'int64'>
}

const decode = typia.protobuf.createDecode<Foo>()

const obj = { id: 12 }
const encoded = typia.protobuf.encode<Foo>(obj)

try {
  const buffer1 = Buffer.from(encoded)
  const decoded1 = decode(buffer1) // throws

  console.log(obj, decoded1)
} catch (e) {
  console.error(e) // Error on typia.protobuf.decode(): buffer overflow
}

// while this works fine.
const buffer2 = Buffer.from(encoded.buffer, encoded.byteOffset, encoded.byteLength)
const decoded2 = decode(buffer2)

console.log(obj, decoded2) // { id: 12 }, { id: 12 }

I tried to patch the constructor code in $ProtobufReader to:

  public constructor(buf: Uint8Array) {
    this.buf = buf;
    this.ptr = 0;
    this.view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
  }

Then decode works fine.

ghlin added a commit to ghlin/typia that referenced this issue Dec 28, 2023
@samchon
Copy link
Owner

samchon commented Dec 28, 2023

Good, waiting for your PR

ghlin added a commit to ghlin/typia that referenced this issue Dec 28, 2023
samchon added a commit that referenced this issue Dec 29, 2023
Fix #912 - protobuf.decode byteOffset
@samchon samchon self-assigned this Dec 29, 2023
@samchon samchon added the enhancement New feature or request label Dec 29, 2023
@samchon samchon added bug Something isn't working good first issue Good for newcomers labels Dec 29, 2023
@samchon
Copy link
Owner

samchon commented Dec 29, 2023

Published to v5.3.6 update.

@samchon samchon closed this as completed Dec 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants