Sonar-scanner not working with virtualbox mounted directories - com.google.protobuf.InvalidProtocolBufferException

Hi All,

I recently switch from Hyper-V (cifs mount) to VirtualBox (virtualbox guest additions driver mount) for a Centos 7 VM. When scanning the code on a mounted directory with sonar-scanner I now get the following error:

INFO: Reading type hierarchy from: /media/sf_git/<redacted>/.scannerwork/ucfg2/php
ERROR: Could not read type hierarchy. The security rules will be skipped. Error:
com.google.protobuf.InvalidProtocolBufferException: While parsing a protocol message, the input ended unexpectedly in the middle of a field.  This could mean either that the input has been truncated or that an embedded message misreported its own length.
        at com.google.protobuf.InvalidProtocolBufferException.truncatedMessage(na:3058)
        at com.google.protobuf.CodedInputStream$StreamDecoder.refillBuffer(na:819)
        at com.google.protobuf.CodedInputStream$StreamDecoder.readStringRequireUtf8(na:2923)
        at org.sonar.types.protobuf.Types$Method.<init>(na:1144)
        at org.sonar.types.protobuf.Types$Method.<init>(na:503)
        at org.sonar.types.protobuf.Types$Method$1.T(na:3456)
        at org.sonar.types.protobuf.Types$Method$1.parsePartialFrom(na:2159)
        at com.google.protobuf.CodedInputStream$StreamDecoder.readMessage(na:2931)
        at org.sonar.types.protobuf.Types$TypeDefinition.<init>(na:733)
        at org.sonar.types.protobuf.Types$TypeDefinition.<init>(na:573)
        at org.sonar.types.protobuf.Types$TypeDefinition$1.U(na:2360)
        at org.sonar.types.protobuf.Types$TypeDefinition$1.parsePartialFrom(na:1319)
        at com.google.protobuf.AbstractParser.parsePartialFrom(na:3542)
        at com.google.protobuf.AbstractParser.parsePartialDelimitedFrom(na:3060)
        at com.google.protobuf.AbstractParser.parseDelimitedFrom(na:3062)
        at com.google.protobuf.AbstractParser.parseDelimitedFrom(na:683)
        at com.google.protobuf.AbstractParser.parseDelimitedFrom(na:1940)
        at com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(na:554)
        at org.sonar.types.protobuf.Types$TypeDefinition.parseDelimitedFrom(na:772)
        at com.sonar.B.A.A(na:3035)
        at com.sonar.security.G.readTypeHierarchy(na:3170)
        at com.sonar.security.G.execute(na:2241)
        at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:45)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:75)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:51)
        at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:68)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:122)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:108)
        at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:421)
        at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:417)
        at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:375)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:122)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:108)
        at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:126)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:122)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:108)
        at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:58)
        at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:52)
        at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
        at com.sun.proxy.$Proxy0.execute(Unknown Source)
        at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
        at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
        at org.sonarsource.scanner.cli.Main.main(Main.java:61)

INFO: Reading UCFGs from: /media/sf_git/<redacted>/.scannerwork/ucfg2/php

Then when importing into Sonarcloud the following error appears:

com.google.protobuf.InvalidProtocolBufferException$InvalidWireTypeException: Protocol message tag had invalid wire type. (Visit failed for Component {key=<redacted>:application/controllers/JsonController.php:BRANCH:develop,type=FILE}  located <redacted>:application/controllers:BRANCH:develop(type=DIRECTORY)-><redacted>:application:BRANCH:develop(type=DIRECTORY)-><redacted>:BRANCH:develop(type=PROJECT))

When running the same code from Windows version of sonar-scanner there is no error. Also, if I copy the source code into another local directory on the same machine and scan it, there is no error.

The biggest issue with these 2 other approaches is that the unit test coverage does not map to the same file paths, so it’s always 0% in SC. Any ideas there would also be appreciated.

Thanks!
Nick

Hi,

It seems that an InvalidProtocolBufferException was raised at 2 different phases of the analysis. The first one didn’t fail the analysis but the second one did.

I think that both exceptions happened at the rare times when we write something to the file system in the directory of the project (SonarScanner create a “.scannerwork” subdirectory).

I suspect that there’s a “low-level” problem when writing to your mounted directory: at least for the 1st exception, it seems that we get unexpected data when we read what we previously wrote to the file system. I never saw such problem before. Maybe you can try to write and read data to the mounted directory inside your VM and check whether the data is correct…

Hi,
Thank you for the reply! That was exactly it, I changed the sonar.working.directory config to a local path on the VM and did not have any errors when scanning.
Thanks again,
Nick

2 Likes