Skip to content

Commit a6dc5de

Browse files
idodeclareVladimir Kotal
authored andcommitted
fix IO exception in readOpening() when reading files longer than 8K (#1844)
1 parent 2517239 commit a6dc5de

File tree

4 files changed

+229
-9
lines changed

4 files changed

+229
-9
lines changed

opengrok-indexer/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
8181
<exclude>*.java</exclude>
8282
</excludes>
8383
</testResource>
84+
<testResource>
85+
<targetPath>org/opensolaris/opengrok/analysis/</targetPath>
86+
<directory>../test/org/opensolaris/opengrok/analysis/</directory>
87+
<excludes>
88+
<exclude>*.java</exclude>
89+
</excludes>
90+
</testResource>
8491
<testResource>
8592
<targetPath>org/opensolaris/opengrok/analysis/perl/</targetPath>
8693
<directory>../test/org/opensolaris/opengrok/analysis/perl/</directory>

src/org/opensolaris/opengrok/analysis/AnalyzerGuru.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,11 @@ public class AnalyzerGuru {
122122
private static final int OPENING_MAX_CHARS = 100;
123123

124124
/**
125-
* Define very close to OPENING_MAX_CHARS so the input stream stays easily
126-
* in the <code>mark</code> limit
125+
* Set to 16K -- though debugging shows it would do with only 8K+3
126+
* (standard buffer for Java BufferedInputStream plus 3 bytes for largest
127+
* UTF BOM)
127128
*/
128-
private static final int OPENING_BUF_SIZE = 102;
129+
private static final int MARK_READ_LIMIT = 1024 * 16;
129130

130131
private static final Logger LOGGER = LoggerFactory.getLogger(AnalyzerGuru.class);
131132

@@ -850,7 +851,7 @@ private static String getWords(String value, int n) {
850851
private static String readOpening(InputStream in, byte[] sig)
851852
throws IOException {
852853

853-
in.mark(512);
854+
in.mark(MARK_READ_LIMIT);
854855

855856
String encoding = IOUtils.findBOMEncoding(sig);
856857
if (encoding == null) {
@@ -871,9 +872,8 @@ private static String readOpening(InputStream in, byte[] sig)
871872

872873
StringBuilder opening = new StringBuilder();
873874
BufferedReader readr = new BufferedReader(
874-
new InputStreamReader(in, encoding), OPENING_BUF_SIZE);
875-
while ((r = readr.read()) != -1)
876-
{
875+
new InputStreamReader(in, encoding), OPENING_MAX_CHARS);
876+
while ((r = readr.read()) != -1) {
877877
if (++nRead > OPENING_MAX_CHARS) break;
878878
char c = (char)r;
879879
boolean isWhitespace = Character.isWhitespace(c);

test/org/opensolaris/opengrok/analysis/AnalyzerGuruTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@
4646
import org.opensolaris.opengrok.analysis.sh.ShAnalyzer;
4747
import org.opensolaris.opengrok.analysis.sh.ShAnalyzerFactory;
4848
import static org.junit.Assert.*;
49-
import java.util.List;
50-
import java.util.ArrayList;
5149

5250
/**
5351
* Tests for the functionality provided by the AnalyzerGuru class.
@@ -243,6 +241,15 @@ public void getAnalyzerFactoryClass() {
243241
assertNull(fc);
244242
}
245243

244+
@Test
245+
public void shouldNotThrowGettingCsprojOpening() throws IOException {
246+
InputStream res = getClass().getClassLoader().getResourceAsStream(
247+
"org/opensolaris/opengrok/analysis/a.csproj");
248+
assertNotNull("despite embedded a.csproj,", res);
249+
assertSame("despite normal a.csproj,", XMLAnalyzer.class,
250+
AnalyzerGuru.getAnalyzer(res, "dummy").getClass());
251+
}
252+
246253
@Test
247254
public void shouldMatchPerlHashbang() throws IOException {
248255
ByteArrayInputStream in = new ByteArrayInputStream(
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{35E89DF8-DDB1-4BF7-A853-DCB3465ECF03}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>SomeLibrary</RootNamespace>
11+
<AssemblyName>SomeLibrary</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<Prefer32Bit>false</Prefer32Bit>
15+
<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
16+
<TargetFrameworkProfile />
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19+
<DebugSymbols>true</DebugSymbols>
20+
<DebugType>full</DebugType>
21+
<Optimize>false</Optimize>
22+
<OutputPath>bin\Debug\</OutputPath>
23+
<DefineConstants>DEBUG;TRACE</DefineConstants>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
<Prefer32Bit>false</Prefer32Bit>
27+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
28+
</PropertyGroup>
29+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>true</Optimize>
32+
<OutputPath>bin\Release\</OutputPath>
33+
<DefineConstants>TRACE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
<Prefer32Bit>false</Prefer32Bit>
37+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
38+
</PropertyGroup>
39+
<ItemGroup>
40+
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
41+
<SpecificVersion>False</SpecificVersion>
42+
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
43+
</Reference>
44+
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
45+
<SpecificVersion>False</SpecificVersion>
46+
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
47+
</Reference>
48+
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
49+
<SpecificVersion>False</SpecificVersion>
50+
<HintPath>..\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
51+
</Reference>
52+
<Reference Include="Microsoft.Owin, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
53+
<SpecificVersion>False</SpecificVersion>
54+
<HintPath>..\packages\Microsoft.Owin.3.0.1\lib\net45\Microsoft.Owin.dll</HintPath>
55+
</Reference>
56+
<Reference Include="Microsoft.Owin.Host.SystemWeb, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
57+
<SpecificVersion>False</SpecificVersion>
58+
<HintPath>..\packages\Microsoft.Owin.Host.SystemWeb.3.0.1\lib\net45\Microsoft.Owin.Host.SystemWeb.dll</HintPath>
59+
</Reference>
60+
<Reference Include="Microsoft.Owin.Security, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
61+
<SpecificVersion>False</SpecificVersion>
62+
<HintPath>..\packages\Microsoft.Owin.Security.3.0.1\lib\net45\Microsoft.Owin.Security.dll</HintPath>
63+
</Reference>
64+
<Reference Include="Owin">
65+
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
66+
</Reference>
67+
<Reference Include="System" />
68+
<Reference Include="System.Core" />
69+
<Reference Include="System.Xml.Linq" />
70+
<Reference Include="System.Data.DataSetExtensions" />
71+
<Reference Include="Microsoft.CSharp" />
72+
<Reference Include="System.Data" />
73+
<Reference Include="System.Data.Services" />
74+
<Reference Include="System.Drawing" />
75+
<Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
76+
<SpecificVersion>False</SpecificVersion>
77+
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
78+
</Reference>
79+
<Reference Include="System.ServiceModel" />
80+
<Reference Include="System.ServiceModel.Activation" />
81+
<Reference Include="System.ServiceModel.Web" />
82+
<Reference Include="System.Transactions" />
83+
<Reference Include="System.Web.Entity" />
84+
<Reference Include="System.Web.ApplicationServices" />
85+
<Reference Include="System.ComponentModel.DataAnnotations" />
86+
<Reference Include="System.Web" />
87+
<Reference Include="System.Web.Abstractions" />
88+
<Reference Include="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
89+
<SpecificVersion>False</SpecificVersion>
90+
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.Helpers.dll</HintPath>
91+
</Reference>
92+
<Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
93+
<SpecificVersion>False</SpecificVersion>
94+
<HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath>
95+
</Reference>
96+
<Reference Include="System.Web.Http.WebHost, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
97+
<SpecificVersion>False</SpecificVersion>
98+
<HintPath>..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.3\lib\net45\System.Web.Http.WebHost.dll</HintPath>
99+
</Reference>
100+
<Reference Include="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
101+
<SpecificVersion>False</SpecificVersion>
102+
<HintPath>..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll</HintPath>
103+
</Reference>
104+
<Reference Include="System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
105+
<SpecificVersion>False</SpecificVersion>
106+
<HintPath>..\packages\Microsoft.AspNet.Razor.3.2.3\lib\net45\System.Web.Razor.dll</HintPath>
107+
</Reference>
108+
<Reference Include="System.Net.Http" />
109+
<Reference Include="System.Web.Routing" />
110+
<Reference Include="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
111+
<SpecificVersion>False</SpecificVersion>
112+
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.dll</HintPath>
113+
</Reference>
114+
<Reference Include="System.Web.WebPages.Deployment, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
115+
<SpecificVersion>False</SpecificVersion>
116+
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Deployment.dll</HintPath>
117+
</Reference>
118+
<Reference Include="System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
119+
<SpecificVersion>False</SpecificVersion>
120+
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Razor.dll</HintPath>
121+
</Reference>
122+
<Reference Include="System.Xml" />
123+
<Reference Include="System.Configuration" />
124+
<Reference Include="System.Runtime.Serialization" />
125+
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
126+
<Private>True</Private>
127+
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
128+
</Reference>
129+
<Reference Include="System.Net.Http.WebRequest">
130+
</Reference>
131+
<Reference Include="System.Web.Optimization">
132+
<HintPath>..\packages\Microsoft.AspNet.Web.Optimization.1.1.3\lib\net40\System.Web.Optimization.dll</HintPath>
133+
</Reference>
134+
<Reference Include="System.Xml.Linq" />
135+
<Reference Include="WebActivatorEx, Version=2.0.0.0, Culture=neutral, PublicKeyToken=7b26dc2a43f6a0d4, processorArchitecture=MSIL">
136+
<SpecificVersion>False</SpecificVersion>
137+
<HintPath>..\packages\WebActivatorEx.2.0.6\lib\net40\WebActivatorEx.dll</HintPath>
138+
</Reference>
139+
<Reference Include="Antlr3.Runtime">
140+
<Private>True</Private>
141+
<HintPath>..\packages\Antlr.3.4.1.9004\lib\Antlr3.Runtime.dll</HintPath>
142+
</Reference>
143+
<Reference Include="WebGrease, Version=1.6.5135.21930, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
144+
<SpecificVersion>False</SpecificVersion>
145+
<HintPath>..\packages\WebGrease.1.6.0\lib\WebGrease.dll</HintPath>
146+
</Reference>
147+
</ItemGroup>
148+
<ItemGroup>
149+
<Compile Include="Properties\AssemblyInfo.cs" />
150+
</ItemGroup>
151+
<ItemGroup>
152+
<None Include="Scripts\jquery-1.10.2.intellisense.js" />
153+
<Content Include="Scripts\jquery-1.10.2.js" />
154+
<Content Include="Scripts\jquery-1.10.2.min.js" />
155+
<Content Include="Scripts\jquery.signalR-2.2.0.js" />
156+
<Content Include="Scripts\jquery.signalR-2.2.0.min.js" />
157+
<Content Include="Scripts\modernizr-2.6.2.js" />
158+
<Content Include="Scripts\respond.js" />
159+
<Content Include="Scripts\respond.min.js" />
160+
<Content Include="Content\Site.css" />
161+
<Content Include="Scripts\_references.js" />
162+
<Content Include="Views\_ViewStart.cshtml" />
163+
<Content Include="Views\Shared\Error.cshtml" />
164+
<Content Include="Views\Shared\_Layout.cshtml" />
165+
<Content Include="Scripts\jquery-1.10.2.min.map" />
166+
</ItemGroup>
167+
<ItemGroup>
168+
<Content Include="fonts\glyphicons-halflings-regular.woff" />
169+
<Content Include="fonts\glyphicons-halflings-regular.ttf" />
170+
<Content Include="fonts\glyphicons-halflings-regular.eot" />
171+
<Content Include="packages.config" />
172+
</ItemGroup>
173+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
174+
<ProjectExtensions>
175+
<VisualStudio>
176+
<FlavorProperties GUID="{0}">
177+
<WebProjectProperties>
178+
<UseIIS>True</UseIIS>
179+
<AutoAssignPort>False</AutoAssignPort>
180+
<DevelopmentServerPort>55555</DevelopmentServerPort>
181+
<DevelopmentServerVPath>/</DevelopmentServerVPath>
182+
<IISUrl>http://localhost/SomeProject</IISUrl>
183+
<NTLMAuthentication>False</NTLMAuthentication>
184+
<UseCustomServer>False</UseCustomServer>
185+
<CustomServerUrl>
186+
</CustomServerUrl>
187+
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
188+
</WebProjectProperties>
189+
</FlavorProperties>
190+
</VisualStudio>
191+
</ProjectExtensions>
192+
<Import Project="..\packages\StyleCop.MSBuild.4.7.49.1\build\StyleCop.MSBuild.Targets" Condition="Exists('..\packages\StyleCop.MSBuild.4.7.49.1\build\StyleCop.MSBuild.Targets')" />
193+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
194+
<PropertyGroup>
195+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
196+
</PropertyGroup>
197+
<Error Condition="!Exists('..\packages\StyleCop.MSBuild.4.7.49.1\build\StyleCop.MSBuild.Targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\StyleCop.MSBuild.4.7.49.1\build\StyleCop.MSBuild.Targets'))" />
198+
</Target>
199+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
200+
Other similar extension points exist, see Microsoft.Common.targets.
201+
<Target Name="BeforeBuild">
202+
</Target>
203+
<Target Name="AfterBuild">
204+
</Target>
205+
-->
206+
</Project>

0 commit comments

Comments
 (0)