chalkos / Marketbuddy

Plugin for XivLauncher/Dalamud to help with your day-to-day market operations.
Apache License 2.0
34 stars 17 forks source link

Control click crashed client when clipboard does not contain plain numbers #16

Closed DenL closed 2 years ago

DenL commented 2 years ago

What are you trying to do?

Control click an adjust listing option (by accident) when clipboard does not contain numbers (or empty clipboard?)

What is the expected behavior?

Program doesn't crash.

What actually happened?

FFXIV client crashed

Suggested solution

Not sure what's the expected output here; perhaps throw out an error message and not adjust price listing?

Logs

No response

FFXIV Update

Cyenia commented 2 years ago

I could not reproduce this with a space, a hexadecimal number or a very long text. Unfortunately, I did not have an empty clipboard and could not test this.

chalkos commented 2 years ago

the clipboard is not the issue.

var cbValue = ImGui.GetClipboardText() ?? "";
if (int.TryParse(cbValue, out var priceValue) && priceValue > 0)
    SetPrice(priceValue);
else
    ChatGui.Print("Marketbuddy: Clipboard does not contain a valid price");

any value that is not a positive integer will show an error in the chat.

@DenL do you have Penny Pincher installed?

DenL commented 2 years ago

I do not. I’ve had it happen a few times when I first opened retainer/marketboard. And control click is the first thing I do.

Apologize for making the false assumption.

Let me play around with it to see how I can reliably reproduce.

DenL commented 2 years ago

I sometimes have images in my clipboard. Could this happen in that case?

Edit: yup i just tested it. Did a couple price adjustments via marketbuddy. Use windows snipping shortcut to put an image in my clipboard. Tried a control click->crash.

Cyenia commented 2 years ago

Can confirm. The ImGui.GetClipboardText() function throws an exception with an image in the clipboard.

Fixed with:

try
{
    var cbValue = ImGui.GetClipboardText() ?? "";
    if (int.TryParse(cbValue, out var priceValue) && priceValue > 0)
        SetPrice(priceValue);
    else
        throw new Exception();
}
catch (Exception)
{
    ChatGui.Print("Marketbuddy: Clipboard does not contain a valid price");
}
chalkos commented 2 years ago

Good find. I'll deploy the fix soon. Thanks for the code suggestion as well!