Skip to content

Fix crash issue when trying to parse bad skin JSON#3712

Open
TheSharkyOfficial wants to merge 17 commits intoPrismarineJS:masterfrom
TheSharkyOfficial:patch-3
Open

Fix crash issue when trying to parse bad skin JSON#3712
TheSharkyOfficial wants to merge 17 commits intoPrismarineJS:masterfrom
TheSharkyOfficial:patch-3

Conversation

@TheSharkyOfficial
Copy link
Contributor

Bad skin JSON sometimes occur with NPC players on servers, this will fix the JSON by adding missing quotes if found.

Example of JSON of a NPC player (notice the missing quotes) :

{textures:{SKIN:{url:"http://textures.minecraft.net/texture/b67168621fdb0cf3f7e57cb5166d48e9e9c87d677494339f3b8feec8c3a36b"}}}

For comparison, this is what a normal player skin data looks like :

{
  "timestamp" : 1754070097924,
  "profileId" : "ec7732e7890547fdae796508b583fef3",
  "profileName" : "wtfsofie",
  "signatureRequired" : true,
  "textures" : {
    "SKIN" : {
      "url" : "http://textures.minecraft.net/texture/c000d56909bcbb3542c65a2eb1b1c4810f907b277d041da2a1b16c894a96030c",
      "metadata" : {
        "model" : "slim"
      }
    },
    "CAPE" : {
      "url" : "http://textures.minecraft.net/texture/cb40a92e32b57fd732a00fc325e7afb00a7ca74936ad50d8e860152e482cfbde"
    }
  }
}```

Bad JSON sometimes occur with NPC players on servers
@extremeheat
Copy link
Member

That should be using mojangson

@rom1504
Copy link
Member

rom1504 commented Aug 2, 2025

@rom1504
Copy link
Member

rom1504 commented Aug 3, 2025

Please remove this custom parsing and use https://github.com/PrismarineJS/node-mojangson instead

Copy link
Contributor

@Omena0 Omena0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the linting errors.

@fungoza
Copy link
Contributor

fungoza commented Oct 12, 2025

bump, this thing still crashes bot without fix

@TheSharkyOfficial
Copy link
Contributor Author

this should fix the crash now


const skinTexture = JSON.parse(Buffer.from(props.textures.value, 'base64').toString('utf8'))

const skinTexture = JSON.parse(mojangson.parse(Buffer.from(props.textures.value, 'base64').toString('utf8')))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the .toString('utf8' and json parse is not necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just made and tested a new fix, because mojangson can't parse JSON, and also only for mojangson formatted skins .toString('utf8') is required because otherwise it would give hex data

@rom1504
Copy link
Member

rom1504 commented Dec 3, 2025

Can you add a test ?

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

Successfully merging this pull request may close these issues.

5 participants