mojira.dev
MC-254774

Crash when a villager with a gossip of value 0 shares gossips

Steps to Reproduce
Execute the following command several times during the daytime: /summon minecraft:villager ~ ~ ~ {Gossips: [{Target: [I; 438831016, 1755662668, -1977558996, -1156852131], Type: "trading", Value: 0}]}

Observed Behavior
Crash occurs

Code analysis
Yarn 1.19.1

In VillagerGossips#pickGossips the nextInt method is called with the sum of the absolute value of all gossip values of a villager. If a villager has a gossip of value 0 only, the sum is 0, causing the crash since nextInt expects a positive integer. There should be an early-return in case the sum is 0. This does not affect villagers without gossips because of the early-return a few lines above, which means this cannot be triggered in survival since no action produces a gossip of value 0.

Attachments

Comments 2

Credit to Silasish from Fabricord for original reporting of the bug!

Can confirm in 1.19.2.

[media]

apple502j

Fantastime

Confirmed

Important

Crash

1.19.1, 1.19.2

22w42a

Retrieved