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

Bad string size caused by missing bytes in registry.bin #432

Closed
lanmaoxinqing opened this issue Jun 17, 2021 · 1 comment
Closed

Bad string size caused by missing bytes in registry.bin #432

lanmaoxinqing opened this issue Jun 17, 2021 · 1 comment
Assignees
Labels
bug Something isn't working
Milestone

Comments

@lanmaoxinqing
Copy link
Contributor

Hi,
We occasionally got a bad string size exception in our ci system showing below

Exception in thread "main" java.lang.IllegalStateException: Bad string size: 29801
	at org.mvndaemon.mvnd.common.DaemonRegistry.readString(DaemonRegistry.java:274)
	at org.mvndaemon.mvnd.common.DaemonRegistry.doUpdate(DaemonRegistry.java:204)
	at org.mvndaemon.mvnd.common.DaemonRegistry.read(DaemonRegistry.java:159)
	at org.mvndaemon.mvnd.common.DaemonRegistry.getAll(DaemonRegistry.java:101)
	at org.mvndaemon.mvnd.client.DaemonConnector.connect(DaemonConnector.java:97)
	at org.mvndaemon.mvnd.client.DefaultClient.execute(DefaultClient.java:233)
	at org.mvndaemon.mvnd.client.DefaultClient.main(DefaultClient.java:98)

In my situation, data keeps correct until reading the missing short bytes, which is the length of reason field, and then crashes. It may still work if the next short bytes is less than 1024 (but the DaemonStopEvent data breaks down since then)

    private String readString() {
        int sz = buffer.getShort();
        if (sz == -1) {
            return null;
        }
        if (sz < -1 || sz > 1024) {  // <-- here
            throw new IllegalStateException("Bad string size: " + sz);
        }
        byte[] buf = new byte[sz];
        buffer.get(buf);
        return new String(buf, StandardCharsets.UTF_8);
    }

image
image

what's worse, all later builds on the same ci machine will crash due to readString exception, until we delete the registry.bin file.

It happens in mvnd 0.4.1, but I think we still suffers in 0.5.1.
The problem registry.bin is in attach file below (I masked some working path info due to sensitive security policy), be sure using 0.4.1 to debug with it (token field add in 0.5.0)
registry.bin.zip

one guess is that mvnd crashed unexpectedly while FileChannel is flushing the file, so it closed and remains incomplete data in registry.bin.

@gnodet gnodet added the bug Something isn't working label Jun 17, 2021
@gnodet
Copy link
Contributor

gnodet commented Jun 17, 2021

It does happen during CI builds:
1_windows.txt

lanmaoxinqing added a commit to lanmaoxinqing/mvnd that referenced this issue Jun 17, 2021
Since the registry data is invalid, i simply empty the content to guarantee the next registry will work correct.
@gnodet gnodet added this to the 0.5.2 milestone Jun 18, 2021
gnodet pushed a commit to gnodet/mvnd that referenced this issue Jun 18, 2021
…pache#433

Fix a possible write a long string in case where the string length is <= 1024 but the encoded size if > 1024.
Truncate long strings and warn instead of throwing an exception which could lead to an invalid registry.
Since the registry data is invalid, the content is emptied to guarantee the next registry will work correct.
This fix is based on apache#435 provided by lanmaoxinqing, many thanks !
gnodet pushed a commit to gnodet/mvnd that referenced this issue Jun 18, 2021
…pache#433

Fix a possible write a long string in case where the string length is <= 1024 but the encoded size if > 1024.
Truncate long strings and warn instead of throwing an exception which could lead to an invalid registry.
Since the registry data is invalid, the content is emptied to guarantee the next registry will work correct.
This fix is based on apache#435 provided by @lanmaoxinqing, many thanks !
@gnodet gnodet closed this as completed in 6de7605 Jun 18, 2021
gnodet added a commit that referenced this issue Jun 18, 2021
Attempt to fix bad registry errors, fixes #432 and #433
@gnodet gnodet self-assigned this Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants