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

ProtobufJS doesn't properly serialise messages #11727

Closed
l1mey112 opened this issue Jun 9, 2024 · 2 comments
Closed

ProtobufJS doesn't properly serialise messages #11727

l1mey112 opened this issue Jun 9, 2024 · 2 comments
Labels
bug Something isn't working needs triage

Comments

@l1mey112
Copy link

l1mey112 commented Jun 9, 2024

What version of Bun is running?

1.1.4+fbe2fe0c3

What platform is your computer?

Linux 6.9.1-arch1-2 x86_64 unknown

What steps can reproduce the bug?

Entire MRE project: test.zip

import { load } from "protobufjs"

const sp = await load(`${import.meta.dir}/sp.proto`)
const signup = sp.lookupType('SignUpRequest')

const msg = {
	url: 'https://auth-callback.spotify.com/r/ios/music/signup',
	tag2: {
		username: 'test',
		dob: `2000-00-00`,
		gender: 1,
		tag4: {
			tag1: {
				blank_tag1: 1
			},
			tag2: {},
			tag3: {},
		},
		tag101: {
			signupemail: 'test@gmail.com',
			password: 'test',
		},
	},
	tag3: {
		client_id: 'test',
		os: 'test',
		appversion: '8.8.54',
		stringoffset: 1,
		random_hex32: 'testing',
	},
	tag4: {
		client_mobile: 'client_mobile',
	},
}

const message = signup.fromObject(msg)
const buf = signup.encode(message).finish()

const message2 = signup.decode(buf)
console.log(message2.toJSON()) // INCORRECT MESSAGE

What is the expected behavior?

Correct printout exactly as encoded.

What do you see instead?

A couple fields are missing:

{
  url: "https://auth-callback.spotify.com/r/ios/music/signup",
  tag2: {
    username: "test",
    dob: "2000-00-00",
    gender: 1,
    tag4: {
      tag1: [Object ...],
      tag2: [Object ...],
      tag3: [Object ...],
    },
    tag101: {
      signupemail: "test@gmail.com",
      password: "test",
    },
  },
  tag3: {
    os: "test",
    appversion: "8.8.54",
    stringoffset: 1,
  },
  tag4: {},
}

Additional information

This might fix #11633 as librespot uses this exact library.

@l1mey112 l1mey112 added bug Something isn't working needs triage labels Jun 9, 2024
@Jarred-Sumner
Copy link
Collaborator

Jarred-Sumner commented Jun 9, 2024

Not a bug in Bun, as Node & Bun produce identical output:

❯ node index.mjs | shasum
4a29eb0666cf574f845e089689e969d1100cb890  -
❯ bun index.mjs | shasum
4a29eb0666cf574f845e089689e969d1100cb890  -
import { createRequire } from "module";

const require = createRequire(import.meta.url);

const { load } = require("protobufjs");

const sp = await load(`${import.meta.dirname}/sp.proto`);
const signup = sp.lookupType("SignUpRequest");

const msg = {
  url: "https://auth-callback.spotify.com/r/ios/music/signup",
  tag2: {
    username: "test",
    dob: `2000-00-00`,
    gender: 1,
    tag4: {
      tag1: {
        blank_tag1: 1,
      },
      tag2: {},
      tag3: {},
    },
    tag101: {
      signupemail: "test@gmail.com",
      password: "test",
    },
  },
  tag3: {
    client_id: "test",
    os: "test",
    appversion: "8.8.54",
    stringoffset: 1,
    random_hex32: "testing",
  },
  tag4: {
    client_mobile: "client_mobile",
  },
};

const message = signup.fromObject(msg);
const buf = signup.encode(message).finish();

const message2 = signup.decode(buf);
process.stdout.write(JSON.stringify(message2.toJSON()));

@Jarred-Sumner Jarred-Sumner closed this as not planned Won't fix, can't repro, duplicate, stale Jun 9, 2024
@sirenkovladd
Copy link
Contributor

protobufjs/protobuf.js#564

this object works

const msg = {
  	url: 'https://auth-callback.spotify.com/r/ios/music/signup',
  	tag2: {
  		username: 'test',
  		dob: `2000-00-00`,
  		gender: 1,
  		tag4: {
  			tag1: {
  				blankTag1: 1
  			},
  			tag2: {},
  			tag3: {},
  		},
  		tag101: {
  			signupemail: 'test@gmail.com',
  			password: 'test',
  		},
  	},
  	tag3: {
  		clientId: 'test',
  		os: 'test',
  		appversion: '8.8.54',
  		stringoffset: 1,
  		randomHex32: 'testing',
  	},
  	tag4: {
  		clientMobile: 'client_mobile',
  	},
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

3 participants