Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- inferredbugs-0000/environment/Dockerfile +0 -5
- inferredbugs-0000/instruction.md +0 -424
- inferredbugs-0001/environment/Dockerfile +0 -5
- inferredbugs-0001/instruction.md +0 -75
- inferredbugs-0002/environment/Dockerfile +0 -5
- inferredbugs-0002/instruction.md +0 -924
- inferredbugs-0003/environment/Dockerfile +0 -5
- inferredbugs-0003/instruction.md +0 -171
- inferredbugs-0004/environment/Dockerfile +0 -5
- inferredbugs-0004/instruction.md +0 -133
- inferredbugs-0005/environment/Dockerfile +0 -5
- inferredbugs-0005/instruction.md +0 -235
- inferredbugs-0006/environment/Dockerfile +0 -5
- inferredbugs-0006/instruction.md +0 -977
- inferredbugs-0007/environment/Dockerfile +0 -5
- inferredbugs-0007/instruction.md +0 -100
- inferredbugs-0008/environment/Dockerfile +0 -5
- inferredbugs-0008/instruction.md +0 -81
- inferredbugs-0009/environment/Dockerfile +0 -5
- inferredbugs-0009/instruction.md +0 -142
- inferredbugs-0010/environment/Dockerfile +0 -5
- inferredbugs-0010/instruction.md +0 -102
- inferredbugs-0011/environment/Dockerfile +0 -5
- inferredbugs-0011/instruction.md +0 -102
- inferredbugs-0012/environment/Dockerfile +0 -5
- inferredbugs-0012/instruction.md +0 -407
- inferredbugs-0013/environment/Dockerfile +0 -5
- inferredbugs-0013/instruction.md +0 -431
- inferredbugs-0014/environment/Dockerfile +0 -5
- inferredbugs-0014/instruction.md +0 -417
- inferredbugs-0015/environment/Dockerfile +0 -5
- inferredbugs-0015/instruction.md +0 -119
- inferredbugs-0016/environment/Dockerfile +0 -5
- inferredbugs-0016/instruction.md +0 -119
- inferredbugs-0017/environment/Dockerfile +0 -5
- inferredbugs-0017/instruction.md +0 -122
- inferredbugs-0018/environment/Dockerfile +0 -5
- inferredbugs-0018/instruction.md +0 -156
- inferredbugs-0019/environment/Dockerfile +0 -5
- inferredbugs-0019/instruction.md +0 -156
- inferredbugs-0020/environment/Dockerfile +0 -5
- inferredbugs-0020/instruction.md +0 -100
- inferredbugs-0021/environment/Dockerfile +0 -5
- inferredbugs-0021/instruction.md +0 -110
- inferredbugs-0022/environment/Dockerfile +0 -5
- inferredbugs-0022/instruction.md +0 -229
- inferredbugs-0023/environment/Dockerfile +0 -5
- inferredbugs-0023/instruction.md +0 -255
- inferredbugs-0024/environment/Dockerfile +0 -5
- inferredbugs-0024/instruction.md +0 -59
inferredbugs-0000/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0000/instruction.md
DELETED
|
@@ -1,424 +0,0 @@
|
|
| 1 |
-
# InferredBugs Task - Csharp
|
| 2 |
-
|
| 3 |
-
## Project Information
|
| 4 |
-
|
| 5 |
-
**Project:** titanium-web-proxy
|
| 6 |
-
**Bug ID:** 1
|
| 7 |
-
**Language:** csharp
|
| 8 |
-
|
| 9 |
-
## Bug Information
|
| 10 |
-
|
| 11 |
-
### File-Level Changes:
|
| 12 |
-
|
| 13 |
-
**Before (Buggy File):**
|
| 14 |
-
```csharp
|
| 15 |
-
using System;
|
| 16 |
-
using System.Collections.Generic;
|
| 17 |
-
using System.Net;
|
| 18 |
-
using System.Runtime.CompilerServices;
|
| 19 |
-
using System.Runtime.InteropServices;
|
| 20 |
-
using System.Text;
|
| 21 |
-
using Titanium.Web.Proxy.Models;
|
| 22 |
-
|
| 23 |
-
namespace Titanium.Web.Proxy.Helpers.WinHttp
|
| 24 |
-
{
|
| 25 |
-
internal sealed class WinHttpWebProxyFinder : IDisposable
|
| 26 |
-
{
|
| 27 |
-
private readonly WinHttpHandle session;
|
| 28 |
-
private bool autoDetectFailed;
|
| 29 |
-
private AutoWebProxyState state;
|
| 30 |
-
|
| 31 |
-
public ICredentials Credentials { get; set; }
|
| 32 |
-
|
| 33 |
-
public ProxyInfo ProxyInfo { get; internal set; }
|
| 34 |
-
|
| 35 |
-
public bool BypassOnLocal { get; internal set; }
|
| 36 |
-
|
| 37 |
-
public Uri AutomaticConfigurationScript { get; internal set; }
|
| 38 |
-
|
| 39 |
-
public bool AutomaticallyDetectSettings { get; internal set; }
|
| 40 |
-
|
| 41 |
-
public WinHttpWebProxyFinder()
|
| 42 |
-
{
|
| 43 |
-
session = NativeMethods.WinHttp.WinHttpOpen(null, NativeMethods.WinHttp.AccessType.NoProxy, null, null, 0);
|
| 44 |
-
if (session == null || session.IsInvalid)
|
| 45 |
-
{
|
| 46 |
-
int lastWin32Error = GetLastWin32Error();
|
| 47 |
-
}
|
| 48 |
-
else
|
| 49 |
-
{
|
| 50 |
-
int downloadTimeout = 60 * 1000;
|
| 51 |
-
if (NativeMethods.WinHttp.WinHttpSetTimeouts(session, downloadTimeout, downloadTimeout, downloadTimeout, downloadTimeout))
|
| 52 |
-
return;
|
| 53 |
-
int lastWin32Error = GetLastWin32Error();
|
| 54 |
-
}
|
| 55 |
-
}
|
| 56 |
-
|
| 57 |
-
public bool GetAutoProxies(Uri destination, out IList<string> proxyList)
|
| 58 |
-
{
|
| 59 |
-
proxyList = null;
|
| 60 |
-
if (session == null || session.IsInvalid || state == AutoWebProxyState.UnrecognizedScheme)
|
| 61 |
-
return false;
|
| 62 |
-
|
| 63 |
-
string proxyListString = null;
|
| 64 |
-
var errorCode = NativeMethods.WinHttp.ErrorCodes.AudodetectionFailed;
|
| 65 |
-
if (AutomaticallyDetectSettings && !autoDetectFailed)
|
| 66 |
-
{
|
| 67 |
-
errorCode = (NativeMethods.WinHttp.ErrorCodes)GetAutoProxies(destination, null, out proxyListString);
|
| 68 |
-
autoDetectFailed = IsErrorFatalForAutoDetect(errorCode);
|
| 69 |
-
if (errorCode == NativeMethods.WinHttp.ErrorCodes.UnrecognizedScheme)
|
| 70 |
-
{
|
| 71 |
-
state = AutoWebProxyState.UnrecognizedScheme;
|
| 72 |
-
return false;
|
| 73 |
-
}
|
| 74 |
-
}
|
| 75 |
-
|
| 76 |
-
if (AutomaticConfigurationScript != null && IsRecoverableAutoProxyError(errorCode))
|
| 77 |
-
errorCode = (NativeMethods.WinHttp.ErrorCodes)GetAutoProxies(destination, AutomaticConfigurationScript, out proxyListString);
|
| 78 |
-
|
| 79 |
-
state = GetStateFromErrorCode(errorCode);
|
| 80 |
-
if (state != AutoWebProxyState.Completed)
|
| 81 |
-
return false;
|
| 82 |
-
|
| 83 |
-
if (!string.IsNullOrEmpty(proxyListString))
|
| 84 |
-
{
|
| 85 |
-
proxyListString = RemoveWhitespaces(proxyListString);
|
| 86 |
-
proxyList = proxyListString.Split(';');
|
| 87 |
-
}
|
| 88 |
-
|
| 89 |
-
return true;
|
| 90 |
-
}
|
| 91 |
-
|
| 92 |
-
public ExternalProxy GetProxy(Uri destination)
|
| 93 |
-
{
|
| 94 |
-
IList<string> proxies;
|
| 95 |
-
if (GetAutoProxies(destination, out proxies))
|
| 96 |
-
{
|
| 97 |
-
if (proxies == null)
|
| 98 |
-
{
|
| 99 |
-
return null;
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
string proxy = proxies[0];
|
| 103 |
-
int port = 80;
|
| 104 |
-
if (proxy.Contains(":"))
|
| 105 |
-
{
|
| 106 |
-
var parts = proxy.Split(new[] { ':' }, 2);
|
| 107 |
-
proxy = parts[0];
|
| 108 |
-
port = int.Parse(parts[1]);
|
| 109 |
-
}
|
| 110 |
-
|
| 111 |
-
// TODO: Apply authorization
|
| 112 |
-
var systemProxy = new ExternalProxy
|
| 113 |
-
{
|
| 114 |
-
HostName = proxy,
|
| 115 |
-
Port = port,
|
| 116 |
-
};
|
| 117 |
-
|
| 118 |
-
return systemProxy;
|
| 119 |
-
}
|
| 120 |
-
|
| 121 |
-
if (IsBypassedManual(destination))
|
| 122 |
-
return null;
|
| 123 |
-
|
| 124 |
-
var protocolType = ProxyInfo.ParseProtocolType(destination.Scheme);
|
| 125 |
-
if (protocolType.HasValue)
|
| 126 |
-
{
|
| 127 |
-
HttpSystemProxyValue value = null;
|
| 128 |
-
if (ProxyInfo?.Proxies?.TryGetValue(protocolType.Value, out value) == true)
|
| 129 |
-
{
|
| 130 |
-
var systemProxy = new ExternalProxy
|
| 131 |
-
{
|
| 132 |
-
HostName = value.HostName,
|
| 133 |
-
Port = value.Port,
|
| 134 |
-
};
|
| 135 |
-
|
| 136 |
-
return systemProxy;
|
| 137 |
-
}
|
| 138 |
-
}
|
| 139 |
-
|
| 140 |
-
return null;
|
| 141 |
-
}
|
| 142 |
-
|
| 143 |
-
public void LoadFromIE()
|
| 144 |
-
{
|
| 145 |
-
var pi = GetProxyInfo();
|
| 146 |
-
ProxyInfo = pi;
|
| 147 |
-
AutomaticallyDetectSettings = pi.AutoDetect == true;
|
| 148 |
-
AutomaticConfigurationScript = pi.AutoConfigUrl == null ? null : new Uri(pi.AutoConfigUrl);
|
| 149 |
-
}
|
| 150 |
-
|
| 151 |
-
private bool IsBypassedManual(Uri host)
|
| 152 |
-
{
|
| 153 |
-
if (host.IsLoopback || BypassOnLocal && IsLocal(host))
|
| 154 |
-
return true;
|
| 155 |
-
|
| 156 |
-
return false;
|
| 157 |
-
}
|
| 158 |
-
|
| 159 |
-
private bool IsLocal(Uri host)
|
| 160 |
-
{
|
| 161 |
-
try
|
| 162 |
-
{
|
| 163 |
-
// get host IP addresses
|
| 164 |
-
IPAddress[] hostIPs = Dns.GetHostAddresses(host.Host);
|
| 165 |
-
|
| 166 |
-
// get local IP addresses
|
| 167 |
-
IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
|
| 168 |
-
|
| 169 |
-
// test if any host IP equals to any local IP or to localhost
|
| 170 |
-
foreach (IPAddress hostIP in hostIPs)
|
| 171 |
-
{
|
| 172 |
-
// is localhost
|
| 173 |
-
if (IPAddress.IsLoopback(hostIP)) return true;
|
| 174 |
-
|
| 175 |
-
// is local address
|
| 176 |
-
foreach (IPAddress localIP in localIPs)
|
| 177 |
-
{
|
| 178 |
-
if (hostIP.Equals(localIP)) return true;
|
| 179 |
-
}
|
| 180 |
-
}
|
| 181 |
-
}
|
| 182 |
-
catch
|
| 183 |
-
{
|
| 184 |
-
}
|
| 185 |
-
|
| 186 |
-
return false;
|
| 187 |
-
}
|
| 188 |
-
|
| 189 |
-
private ProxyInfo GetProxyInfo()
|
| 190 |
-
{
|
| 191 |
-
var proxyConfig = new NativeMethods.WinHttp.WINHTTP_CURRENT_USER_IE_PROXY_CONFIG();
|
| 192 |
-
RuntimeHelpers.PrepareConstrainedRegions();
|
| 193 |
-
try
|
| 194 |
-
{
|
| 195 |
-
ProxyInfo result;
|
| 196 |
-
if (NativeMethods.WinHttp.WinHttpGetIEProxyConfigForCurrentUser(ref proxyConfig))
|
| 197 |
-
{
|
| 198 |
-
result = new ProxyInfo(
|
| 199 |
-
proxyConfig.AutoDetect,
|
| 200 |
-
Marshal.PtrToStringUni(proxyConfig.AutoConfigUrl),
|
| 201 |
-
null,
|
| 202 |
-
Marshal.PtrToStringUni(proxyConfig.Proxy),
|
| 203 |
-
Marshal.PtrToStringUni(proxyConfig.ProxyBypass));
|
| 204 |
-
}
|
| 205 |
-
else
|
| 206 |
-
{
|
| 207 |
-
if (Marshal.GetLastWin32Error() == 8)
|
| 208 |
-
throw new OutOfMemoryException();
|
| 209 |
-
|
| 210 |
-
result = new ProxyInfo(true, null, null, null, null);
|
| 211 |
-
}
|
| 212 |
-
|
| 213 |
-
return result;
|
| 214 |
-
}
|
| 215 |
-
finally
|
| 216 |
-
{
|
| 217 |
-
Marshal.FreeHGlobal(proxyConfig.Proxy);
|
| 218 |
-
Marshal.FreeHGlobal(proxyConfig.ProxyBypass);
|
| 219 |
-
Marshal.FreeHGlobal(proxyConfig.AutoConfigUrl);
|
| 220 |
-
}
|
| 221 |
-
}
|
| 222 |
-
|
| 223 |
-
public void Reset()
|
| 224 |
-
{
|
| 225 |
-
state = AutoWebProxyState.Uninitialized;
|
| 226 |
-
autoDetectFailed = false;
|
| 227 |
-
}
|
| 228 |
-
|
| 229 |
-
public void Dispose()
|
| 230 |
-
{
|
| 231 |
-
Dispose(true);
|
| 232 |
-
}
|
| 233 |
-
|
| 234 |
-
private void Dispose(bool disposing)
|
| 235 |
-
{
|
| 236 |
-
if (!disposing || session == null || session.IsInvalid)
|
| 237 |
-
return;
|
| 238 |
-
session.Close();
|
| 239 |
-
}
|
| 240 |
-
|
| 241 |
-
private int GetAutoProxies(Uri destination, Uri scriptLocation, out string proxyListString)
|
| 242 |
-
{
|
| 243 |
-
int num = 0;
|
| 244 |
-
var autoProxyOptions = new NativeMethods.WinHttp.WINHTTP_AUTOPROXY_OPTIONS();
|
| 245 |
-
autoProxyOptions.AutoLogonIfChallenged = false;
|
| 246 |
-
if (scriptLocation == null)
|
| 247 |
-
{
|
| 248 |
-
autoProxyOptions.Flags = NativeMethods.WinHttp.AutoProxyFlags.AutoDetect;
|
| 249 |
-
autoProxyOptions.AutoConfigUrl = null;
|
| 250 |
-
autoProxyOptions.AutoDetectFlags = NativeMethods.WinHttp.AutoDetectType.Dhcp | NativeMethods.WinHttp.AutoDetectType.DnsA;
|
| 251 |
-
}
|
| 252 |
-
else
|
| 253 |
-
{
|
| 254 |
-
autoProxyOptions.Flags = NativeMethods.WinHttp.AutoProxyFlags.AutoProxyConfigUrl;
|
| 255 |
-
autoProxyOptions.AutoConfigUrl = scriptLocation.ToString();
|
| 256 |
-
autoProxyOptions.AutoDetectFlags = NativeMethods.WinHttp.AutoDetectType.None;
|
| 257 |
-
}
|
| 258 |
-
|
| 259 |
-
if (!WinHttpGetProxyForUrl(destination.ToString(), ref autoProxyOptions, out proxyListString))
|
| 260 |
-
{
|
| 261 |
-
num = GetLastWin32Error();
|
| 262 |
-
|
| 263 |
-
if (num == (int)NativeMethods.WinHttp.ErrorCodes.LoginFailure && Credentials != null)
|
| 264 |
-
{
|
| 265 |
-
autoProxyOptions.AutoLogonIfChallenged = true;
|
| 266 |
-
if (!WinHttpGetProxyForUrl(destination.ToString(), ref autoProxyOptions, out proxyListString))
|
| 267 |
-
num = GetLastWin32Error();
|
| 268 |
-
}
|
| 269 |
-
}
|
| 270 |
-
|
| 271 |
-
return num;
|
| 272 |
-
}
|
| 273 |
-
|
| 274 |
-
private bool WinHttpGetProxyForUrl(string destination, ref NativeMethods.WinHttp.WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions, out string proxyListString)
|
| 275 |
-
{
|
| 276 |
-
proxyListString = null;
|
| 277 |
-
bool flag;
|
| 278 |
-
var proxyInfo = new NativeMethods.WinHttp.WINHTTP_PROXY_INFO();
|
| 279 |
-
RuntimeHelpers.PrepareConstrainedRegions();
|
| 280 |
-
try
|
| 281 |
-
{
|
| 282 |
-
flag = NativeMethods.WinHttp.WinHttpGetProxyForUrl(session, destination, ref autoProxyOptions, out proxyInfo);
|
| 283 |
-
if (flag)
|
| 284 |
-
proxyListString = Marshal.PtrToStringUni(proxyInfo.Proxy);
|
| 285 |
-
}
|
| 286 |
-
finally
|
| 287 |
-
{
|
| 288 |
-
Marshal.FreeHGlobal(proxyInfo.Proxy);
|
| 289 |
-
Marshal.FreeHGlobal(proxyInfo.ProxyBypass);
|
| 290 |
-
}
|
| 291 |
-
return flag;
|
| 292 |
-
}
|
| 293 |
-
|
| 294 |
-
private static int GetLastWin32Error()
|
| 295 |
-
{
|
| 296 |
-
int lastWin32Error = Marshal.GetLastWin32Error();
|
| 297 |
-
if (lastWin32Error == 8)
|
| 298 |
-
throw new OutOfMemoryException();
|
| 299 |
-
return lastWin32Error;
|
| 300 |
-
}
|
| 301 |
-
|
| 302 |
-
private static bool IsRecoverableAutoProxyError(NativeMethods.WinHttp.ErrorCodes errorCode)
|
| 303 |
-
{
|
| 304 |
-
switch (errorCode)
|
| 305 |
-
{
|
| 306 |
-
case NativeMethods.WinHttp.ErrorCodes.AutoProxyServiceError:
|
| 307 |
-
case NativeMethods.WinHttp.ErrorCodes.AudodetectionFailed:
|
| 308 |
-
case NativeMethods.WinHttp.ErrorCodes.BadAutoProxyScript:
|
| 309 |
-
case NativeMethods.WinHttp.ErrorCodes.UnableToDownloadScript:
|
| 310 |
-
case NativeMethods.WinHttp.ErrorCodes.LoginFailure:
|
| 311 |
-
case NativeMethods.WinHttp.ErrorCodes.OperationCancelled:
|
| 312 |
-
case NativeMethods.WinHttp.ErrorCodes.Timeout:
|
| 313 |
-
case NativeMethods.WinHttp.ErrorCodes.UnrecognizedScheme:
|
| 314 |
-
return true;
|
| 315 |
-
default:
|
| 316 |
-
return false;
|
| 317 |
-
}
|
| 318 |
-
}
|
| 319 |
-
|
| 320 |
-
private static AutoWebProxyState GetStateFromErrorCode(NativeMethods.WinHttp.ErrorCodes errorCode)
|
| 321 |
-
{
|
| 322 |
-
if (errorCode == 0L)
|
| 323 |
-
return AutoWebProxyState.Completed;
|
| 324 |
-
switch (errorCode)
|
| 325 |
-
{
|
| 326 |
-
case NativeMethods.WinHttp.ErrorCodes.UnableToDownloadScript:
|
| 327 |
-
return AutoWebProxyState.DownloadFailure;
|
| 328 |
-
case NativeMethods.WinHttp.ErrorCodes.AutoProxyServiceError:
|
| 329 |
-
case NativeMethods.WinHttp.ErrorCodes.InvalidUrl:
|
| 330 |
-
case NativeMethods.WinHttp.ErrorCodes.BadAutoProxyScript:
|
| 331 |
-
return AutoWebProxyState.Completed;
|
| 332 |
-
case NativeMethods.WinHttp.ErrorCodes.AudodetectionFailed:
|
| 333 |
-
return AutoWebProxyState.DiscoveryFailure;
|
| 334 |
-
case NativeMethods.WinHttp.ErrorCodes.UnrecognizedScheme:
|
| 335 |
-
return AutoWebProxyState.UnrecognizedScheme;
|
| 336 |
-
default:
|
| 337 |
-
return AutoWebProxyState.CompilationFailure;
|
| 338 |
-
}
|
| 339 |
-
}
|
| 340 |
-
|
| 341 |
-
private static string RemoveWhitespaces(string value)
|
| 342 |
-
{
|
| 343 |
-
var stringBuilder = new StringBuilder();
|
| 344 |
-
foreach (char c in value)
|
| 345 |
-
{
|
| 346 |
-
if (!char.IsWhiteSpace(c))
|
| 347 |
-
stringBuilder.Append(c);
|
| 348 |
-
}
|
| 349 |
-
|
| 350 |
-
return stringBuilder.ToString();
|
| 351 |
-
}
|
| 352 |
-
|
| 353 |
-
private static bool IsErrorFatalForAutoDetect(NativeMethods.WinHttp.ErrorCodes errorCode)
|
| 354 |
-
{
|
| 355 |
-
switch (errorCode)
|
| 356 |
-
{
|
| 357 |
-
case NativeMethods.WinHttp.ErrorCodes.BadAutoProxyScript:
|
| 358 |
-
case NativeMethods.WinHttp.ErrorCodes.AutoProxyServiceError:
|
| 359 |
-
case NativeMethods.WinHttp.ErrorCodes.Success:
|
| 360 |
-
case NativeMethods.WinHttp.ErrorCodes.InvalidUrl:
|
| 361 |
-
return false;
|
| 362 |
-
default:
|
| 363 |
-
return true;
|
| 364 |
-
}
|
| 365 |
-
}
|
| 366 |
-
|
| 367 |
-
private enum AutoWebProxyState
|
| 368 |
-
{
|
| 369 |
-
Uninitialized,
|
| 370 |
-
DiscoveryFailure,
|
| 371 |
-
DownloadFailure,
|
| 372 |
-
CompilationFailure,
|
| 373 |
-
UnrecognizedScheme,
|
| 374 |
-
Completed,
|
| 375 |
-
}
|
| 376 |
-
}
|
| 377 |
-
}
|
| 378 |
-
```
|
| 379 |
-
|
| 380 |
-
### Bug Type:
|
| 381 |
-
NULL_DEREFERENCE
|
| 382 |
-
|
| 383 |
-
### Qualifier:
|
| 384 |
-
pointer `value` last assigned on line 113 could be null and is dereferenced at line 116, column 21.
|
| 385 |
-
|
| 386 |
-
### Severity:
|
| 387 |
-
ERROR
|
| 388 |
-
|
| 389 |
-
### Procedure:
|
| 390 |
-
ExternalProxy WinHttpWebProxyFinder.GetProxy(Uri)
|
| 391 |
-
|
| 392 |
-
### File:
|
| 393 |
-
Titanium.Web.Proxy/Helpers/WinHttp/WinHttpWebProxyFinder.cs
|
| 394 |
-
|
| 395 |
-
### Key:
|
| 396 |
-
WinHttpWebProxyFinder.cs|GetProxy|NULL_DEREFERENCE
|
| 397 |
-
|
| 398 |
-
### Node Key:
|
| 399 |
-
cd8a0bceec840cacc5b5d301e25d2255
|
| 400 |
-
|
| 401 |
-
### Hash:
|
| 402 |
-
907215931e8338efcc1f3ff7df8272d5
|
| 403 |
-
|
| 404 |
-
### Bug Type Hum:
|
| 405 |
-
Null Dereference
|
| 406 |
-
|
| 407 |
-
## Task
|
| 408 |
-
|
| 409 |
-
Analyze the bug information provided above. Your task is to:
|
| 410 |
-
|
| 411 |
-
1. **Understand the Bug**: Examine the buggy code and identify what the issue was
|
| 412 |
-
2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
|
| 413 |
-
3. **Evaluate the Fix**: Understand how the after code addresses the issue
|
| 414 |
-
4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
|
| 415 |
-
|
| 416 |
-
### Analysis Questions:
|
| 417 |
-
- What was the specific bug or issue in the original code?
|
| 418 |
-
- What scenarios would trigger this bug?
|
| 419 |
-
- How does the fix address the root cause?
|
| 420 |
-
- Are there any potential edge cases the fix might miss?
|
| 421 |
-
- What coding practices could have prevented this bug?
|
| 422 |
-
- Are there alternative ways to implement the fix?
|
| 423 |
-
|
| 424 |
-
Use the provided environment to explore, test, or reproduce the bug if needed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0001/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0001/instruction.md
DELETED
|
@@ -1,75 +0,0 @@
|
|
| 1 |
-
# InferredBugs Task - Csharp
|
| 2 |
-
|
| 3 |
-
## Project Information
|
| 4 |
-
|
| 5 |
-
**Project:** Oxygen-Dapr
|
| 6 |
-
**Bug ID:** 1
|
| 7 |
-
**Language:** csharp
|
| 8 |
-
|
| 9 |
-
## Bug Information
|
| 10 |
-
|
| 11 |
-
### File-Level Changes:
|
| 12 |
-
|
| 13 |
-
**Before (Buggy File):**
|
| 14 |
-
```csharp
|
| 15 |
-
using Oxygen.Client.ServerSymbol.Events;
|
| 16 |
-
using Oxygen.Common.Implements;
|
| 17 |
-
using Oxygen.Common.Interface;
|
| 18 |
-
using System;
|
| 19 |
-
using System.Collections.Generic;
|
| 20 |
-
using System.Linq;
|
| 21 |
-
using System.Text;
|
| 22 |
-
using System.Threading.Tasks;
|
| 23 |
-
|
| 24 |
-
namespace Oxygen.Server.Kestrel.Implements
|
| 25 |
-
{
|
| 26 |
-
public static class EventHandleRequestExtension
|
| 27 |
-
{
|
| 28 |
-
static Lazy<ISerialize> serialize = new Lazy<ISerialize>(() =>
|
| 29 |
-
{
|
| 30 |
-
return OxygenIocContainer.Resolve<ISerialize>();
|
| 31 |
-
});
|
| 32 |
-
public static T GetData<T>(this EventHandleRequest<T> handleRequest) where T : class
|
| 33 |
-
{
|
| 34 |
-
if (handleRequest == null || string.IsNullOrEmpty(handleRequest.data))
|
| 35 |
-
return default;
|
| 36 |
-
else
|
| 37 |
-
{
|
| 38 |
-
return serialize.Value.DeserializesJson<T>(handleRequest.data);
|
| 39 |
-
}
|
| 40 |
-
}
|
| 41 |
-
}
|
| 42 |
-
}
|
| 43 |
-
|
| 44 |
-
```
|
| 45 |
-
|
| 46 |
-
### Bug Type:
|
| 47 |
-
NULL_DEREFERENCE
|
| 48 |
-
|
| 49 |
-
### Qualifier:
|
| 50 |
-
pointer `request` last assigned on line 22 could be null and is dereferenced at line 23, column 13.
|
| 51 |
-
|
| 52 |
-
### Severity:
|
| 53 |
-
ERROR
|
| 54 |
-
|
| 55 |
-
### Procedure:
|
| 56 |
-
T EventHandleRequestExtension.GetData(EventHandleRequest`1<T>)
|
| 57 |
-
|
| 58 |
-
### File:
|
| 59 |
-
src/Oxygen.Client/Oxygen.Client.ServerSymbol/Events/EventHandleRequestExtension.cs
|
| 60 |
-
|
| 61 |
-
### Key:
|
| 62 |
-
EventHandleRequestExtension.cs|GetData|NULL_DEREFERENCE
|
| 63 |
-
|
| 64 |
-
### Node Key:
|
| 65 |
-
5f52b94101ac56a7bdd970b9fdb5bec8
|
| 66 |
-
|
| 67 |
-
### Hash:
|
| 68 |
-
604d37faca039efa032319f2d22195aa
|
| 69 |
-
|
| 70 |
-
### Bug Type Hum:
|
| 71 |
-
Null Dereference
|
| 72 |
-
|
| 73 |
-
## Task
|
| 74 |
-
|
| 75 |
-
Fix the bug in the code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0002/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0002/instruction.md
DELETED
|
@@ -1,924 +0,0 @@
|
|
| 1 |
-
# InferredBugs Task - Csharp
|
| 2 |
-
|
| 3 |
-
## Project Information
|
| 4 |
-
|
| 5 |
-
**Project:** WatsonTcp
|
| 6 |
-
**Bug ID:** 1
|
| 7 |
-
**Language:** csharp
|
| 8 |
-
|
| 9 |
-
## Bug Information
|
| 10 |
-
|
| 11 |
-
### File-Level Changes:
|
| 12 |
-
|
| 13 |
-
**Before (Buggy File):**
|
| 14 |
-
```csharp
|
| 15 |
-
using System;
|
| 16 |
-
using System.Collections.Concurrent;
|
| 17 |
-
using System.Collections.Generic;
|
| 18 |
-
using System.IO;
|
| 19 |
-
using System.Linq;
|
| 20 |
-
using System.Net;
|
| 21 |
-
using System.Net.Sockets;
|
| 22 |
-
using System.Text;
|
| 23 |
-
using System.Threading;
|
| 24 |
-
using System.Threading.Tasks;
|
| 25 |
-
|
| 26 |
-
namespace WatsonTcp
|
| 27 |
-
{
|
| 28 |
-
/// <summary>
|
| 29 |
-
/// Watson TCP server.
|
| 30 |
-
/// </summary>
|
| 31 |
-
public class WatsonTcpServer : IDisposable
|
| 32 |
-
{
|
| 33 |
-
#region Public-Members
|
| 34 |
-
|
| 35 |
-
#endregion
|
| 36 |
-
|
| 37 |
-
#region Private-Members
|
| 38 |
-
|
| 39 |
-
// Flag: Has Dispose already been called?
|
| 40 |
-
private bool disposed = false;
|
| 41 |
-
|
| 42 |
-
private bool _Debug;
|
| 43 |
-
private string _ListenerIp;
|
| 44 |
-
private int _ListenerPort;
|
| 45 |
-
private IPAddress _ListenerIpAddress;
|
| 46 |
-
private TcpListener _Listener;
|
| 47 |
-
private int _ActiveClients;
|
| 48 |
-
private ConcurrentDictionary<string, ClientMetadata> _Clients;
|
| 49 |
-
private List<string> _PermittedIps;
|
| 50 |
-
private CancellationTokenSource _TokenSource;
|
| 51 |
-
private CancellationToken _Token;
|
| 52 |
-
private Func<string, bool> _ClientConnected = null;
|
| 53 |
-
private Func<string, bool> _ClientDisconnected = null;
|
| 54 |
-
private Func<string, byte[], bool> _MessageReceived = null;
|
| 55 |
-
|
| 56 |
-
#endregion
|
| 57 |
-
|
| 58 |
-
#region Constructors-and-Factories
|
| 59 |
-
|
| 60 |
-
/// <summary>
|
| 61 |
-
/// Initialize the Watson TCP server.
|
| 62 |
-
/// </summary>
|
| 63 |
-
/// <param name="listenerIp">The IP address on which the server should listen, nullable.</param>
|
| 64 |
-
/// <param name="listenerPort">The TCP port on which the server should listen.</param>
|
| 65 |
-
/// <param name="clientConnected">Function to be called when a client connects.</param>
|
| 66 |
-
/// <param name="clientDisconnected">Function to be called when a client disconnects.</param>
|
| 67 |
-
/// <param name="messageReceived">Function to be called when a message is received.</param>
|
| 68 |
-
/// <param name="debug">Enable or debug logging messages.</param>
|
| 69 |
-
public WatsonTcpServer(
|
| 70 |
-
string listenerIp,
|
| 71 |
-
int listenerPort,
|
| 72 |
-
Func<string, bool> clientConnected,
|
| 73 |
-
Func<string, bool> clientDisconnected,
|
| 74 |
-
Func<string, byte[], bool> messageReceived,
|
| 75 |
-
bool debug)
|
| 76 |
-
: this(listenerIp, listenerPort, null, clientConnected, clientDisconnected, messageReceived, debug)
|
| 77 |
-
{
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
/// <summary>
|
| 81 |
-
/// Initialize the Watson TCP server.
|
| 82 |
-
/// </summary>
|
| 83 |
-
/// <param name="listenerIp">The IP address on which the server should listen, nullable.</param>
|
| 84 |
-
/// <param name="listenerPort">The TCP port on which the server should listen.</param>
|
| 85 |
-
/// <param name="permittedIps">List of IP address strings that are allowed to connect (null to permit all).</param>
|
| 86 |
-
/// <param name="clientConnected">Function to be called when a client connects.</param>
|
| 87 |
-
/// <param name="clientDisconnected">Function to be called when a client disconnects.</param>
|
| 88 |
-
/// <param name="messageReceived">Function to be called when a message is received.</param>
|
| 89 |
-
/// <param name="debug">Enable or debug logging messages.</param>
|
| 90 |
-
public WatsonTcpServer(
|
| 91 |
-
string listenerIp,
|
| 92 |
-
int listenerPort,
|
| 93 |
-
IEnumerable<string> permittedIps,
|
| 94 |
-
Func<string, bool> clientConnected,
|
| 95 |
-
Func<string, bool> clientDisconnected,
|
| 96 |
-
Func<string, byte[], bool> messageReceived,
|
| 97 |
-
bool debug)
|
| 98 |
-
{
|
| 99 |
-
if (listenerPort < 1) throw new ArgumentOutOfRangeException(nameof(listenerPort));
|
| 100 |
-
if (messageReceived == null) throw new ArgumentNullException(nameof(_MessageReceived));
|
| 101 |
-
|
| 102 |
-
_ClientConnected = clientConnected;
|
| 103 |
-
_ClientDisconnected = clientDisconnected;
|
| 104 |
-
_MessageReceived = messageReceived;
|
| 105 |
-
|
| 106 |
-
_Debug = debug;
|
| 107 |
-
|
| 108 |
-
if (permittedIps != null && permittedIps.Count() > 0) _PermittedIps = new List<string>(permittedIps);
|
| 109 |
-
|
| 110 |
-
if (String.IsNullOrEmpty(listenerIp))
|
| 111 |
-
{
|
| 112 |
-
_ListenerIpAddress = IPAddress.Any;
|
| 113 |
-
_ListenerIp = _ListenerIpAddress.ToString();
|
| 114 |
-
}
|
| 115 |
-
else
|
| 116 |
-
{
|
| 117 |
-
_ListenerIpAddress = IPAddress.Parse(listenerIp);
|
| 118 |
-
_ListenerIp = listenerIp;
|
| 119 |
-
}
|
| 120 |
-
|
| 121 |
-
_ListenerPort = listenerPort;
|
| 122 |
-
|
| 123 |
-
Log("WatsonTcpServer starting on " + _ListenerIp + ":" + _ListenerPort);
|
| 124 |
-
|
| 125 |
-
_Listener = new TcpListener(_ListenerIpAddress, _ListenerPort);
|
| 126 |
-
_TokenSource = new CancellationTokenSource();
|
| 127 |
-
_Token = _TokenSource.Token;
|
| 128 |
-
_ActiveClients = 0;
|
| 129 |
-
_Clients = new ConcurrentDictionary<string, ClientMetadata>();
|
| 130 |
-
|
| 131 |
-
_Listener.Start();
|
| 132 |
-
WaitForClients();
|
| 133 |
-
}
|
| 134 |
-
|
| 135 |
-
#endregion
|
| 136 |
-
|
| 137 |
-
#region Public-Methods
|
| 138 |
-
|
| 139 |
-
/// <summary>
|
| 140 |
-
/// Tear down the server and dispose of background workers.
|
| 141 |
-
/// </summary>
|
| 142 |
-
public void Dispose()
|
| 143 |
-
{
|
| 144 |
-
Dispose(true);
|
| 145 |
-
GC.SuppressFinalize(this);
|
| 146 |
-
}
|
| 147 |
-
|
| 148 |
-
/// <summary>
|
| 149 |
-
/// Send data to the specified client.
|
| 150 |
-
/// </summary>
|
| 151 |
-
/// <param name="ipPort">IP:port of the recipient client.</param>
|
| 152 |
-
/// <param name="data">Byte array containing data.</param>
|
| 153 |
-
/// <returns>Boolean indicating if the message was sent successfully.</returns>
|
| 154 |
-
public bool Send(string ipPort, byte[] data)
|
| 155 |
-
{
|
| 156 |
-
ClientMetadata client;
|
| 157 |
-
if (!_Clients.TryGetValue(ipPort, out client))
|
| 158 |
-
{
|
| 159 |
-
Log("Send unable to find client " + ipPort);
|
| 160 |
-
return false;
|
| 161 |
-
}
|
| 162 |
-
|
| 163 |
-
return MessageWrite(client, data);
|
| 164 |
-
}
|
| 165 |
-
|
| 166 |
-
/// <summary>
|
| 167 |
-
/// Send data to the specified client, asynchronously.
|
| 168 |
-
/// </summary>
|
| 169 |
-
/// <param name="ipPort">IP:port of the recipient client.</param>
|
| 170 |
-
/// <param name="data">Byte array containing data.</param>
|
| 171 |
-
/// <returns>Task with Boolean indicating if the message was sent successfully.</returns>
|
| 172 |
-
public async Task<bool> SendAsync(string ipPort, byte[] data)
|
| 173 |
-
{
|
| 174 |
-
ClientMetadata client;
|
| 175 |
-
if (!_Clients.TryGetValue(ipPort, out client))
|
| 176 |
-
{
|
| 177 |
-
Log("Send unable to find client " + ipPort);
|
| 178 |
-
return false;
|
| 179 |
-
}
|
| 180 |
-
|
| 181 |
-
return await MessageWriteAsync(client, data);
|
| 182 |
-
}
|
| 183 |
-
|
| 184 |
-
/// <summary>
|
| 185 |
-
/// Determine whether or not the specified client is connected to the server.
|
| 186 |
-
/// </summary>
|
| 187 |
-
/// <returns>Boolean indicating if the client is connected to the server.</returns>
|
| 188 |
-
public bool IsClientConnected(string ipPort)
|
| 189 |
-
{
|
| 190 |
-
ClientMetadata client;
|
| 191 |
-
return (_Clients.TryGetValue(ipPort, out client));
|
| 192 |
-
}
|
| 193 |
-
|
| 194 |
-
/// <summary>
|
| 195 |
-
/// List the IP:port of each connected client.
|
| 196 |
-
/// </summary>
|
| 197 |
-
/// <returns>A string list containing each client IP:port.</returns>
|
| 198 |
-
public List<string> ListClients()
|
| 199 |
-
{
|
| 200 |
-
Dictionary<string, ClientMetadata> clients = _Clients.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
|
| 201 |
-
List<string> ret = new List<string>();
|
| 202 |
-
foreach (KeyValuePair<string, ClientMetadata> curr in clients)
|
| 203 |
-
{
|
| 204 |
-
ret.Add(curr.Key);
|
| 205 |
-
}
|
| 206 |
-
return ret;
|
| 207 |
-
}
|
| 208 |
-
|
| 209 |
-
/// <summary>
|
| 210 |
-
/// Disconnects the specified client.
|
| 211 |
-
/// </summary>
|
| 212 |
-
public void DisconnectClient(string ipPort)
|
| 213 |
-
{
|
| 214 |
-
ClientMetadata client;
|
| 215 |
-
if (!_Clients.TryGetValue(ipPort, out client))
|
| 216 |
-
{
|
| 217 |
-
Log("Disconnect unable to find client " + ipPort);
|
| 218 |
-
}
|
| 219 |
-
else
|
| 220 |
-
{
|
| 221 |
-
client.TcpClient.Close();
|
| 222 |
-
}
|
| 223 |
-
}
|
| 224 |
-
|
| 225 |
-
#endregion
|
| 226 |
-
|
| 227 |
-
#region Private-Methods
|
| 228 |
-
|
| 229 |
-
protected virtual void Dispose(bool disposing)
|
| 230 |
-
{
|
| 231 |
-
if (disposed)
|
| 232 |
-
return;
|
| 233 |
-
|
| 234 |
-
if (disposing)
|
| 235 |
-
{
|
| 236 |
-
_TokenSource.Cancel();
|
| 237 |
-
}
|
| 238 |
-
|
| 239 |
-
disposed = true;
|
| 240 |
-
}
|
| 241 |
-
|
| 242 |
-
private void Log(string msg)
|
| 243 |
-
{
|
| 244 |
-
if (_Debug)
|
| 245 |
-
{
|
| 246 |
-
Console.WriteLine(msg);
|
| 247 |
-
}
|
| 248 |
-
}
|
| 249 |
-
|
| 250 |
-
private void LogException(string method, Exception e)
|
| 251 |
-
{
|
| 252 |
-
Log("================================================================================");
|
| 253 |
-
Log(" = Method: " + method);
|
| 254 |
-
Log(" = Exception Type: " + e.GetType().ToString());
|
| 255 |
-
Log(" = Exception Data: " + e.Data);
|
| 256 |
-
Log(" = Inner Exception: " + e.InnerException);
|
| 257 |
-
Log(" = Exception Message: " + e.Message);
|
| 258 |
-
Log(" = Exception Source: " + e.Source);
|
| 259 |
-
Log(" = Exception StackTrace: " + e.StackTrace);
|
| 260 |
-
Log("================================================================================");
|
| 261 |
-
}
|
| 262 |
-
|
| 263 |
-
private string BytesToHex(byte[] data)
|
| 264 |
-
{
|
| 265 |
-
if (data == null || data.Length < 1) return "(null)";
|
| 266 |
-
return BitConverter.ToString(data).Replace("-", "");
|
| 267 |
-
}
|
| 268 |
-
|
| 269 |
-
private void WaitForClients()
|
| 270 |
-
{
|
| 271 |
-
_Listener.BeginAcceptTcpClient(new AsyncCallback(OnClientConnected), null);
|
| 272 |
-
}
|
| 273 |
-
|
| 274 |
-
private void OnClientConnected(IAsyncResult asyncResult)
|
| 275 |
-
{
|
| 276 |
-
ClientMetadata client = null;
|
| 277 |
-
try
|
| 278 |
-
{
|
| 279 |
-
TcpClient clientSocket = _Listener.EndAcceptTcpClient(asyncResult);
|
| 280 |
-
client = new ClientMetadata(clientSocket);
|
| 281 |
-
|
| 282 |
-
Log("OnClientConnected received connection from: " + client.IpPort);
|
| 283 |
-
|
| 284 |
-
string clientIp = ((IPEndPoint)client.TcpClient.Client.RemoteEndPoint).Address.ToString();
|
| 285 |
-
if (IsAllowedIp(clientIp))
|
| 286 |
-
{
|
| 287 |
-
FinaliseConnection(client);
|
| 288 |
-
}
|
| 289 |
-
else
|
| 290 |
-
{
|
| 291 |
-
Log("*** OnClientConnected rejecting connection from " + clientIp + " (not permitted)");
|
| 292 |
-
client.TcpClient.Close();
|
| 293 |
-
}
|
| 294 |
-
}
|
| 295 |
-
catch (SocketException ex)
|
| 296 |
-
{
|
| 297 |
-
Log("OnClientConnected socket exception from " + client.IpPort + Environment.NewLine + ex.ToString());
|
| 298 |
-
}
|
| 299 |
-
catch (Exception ex)
|
| 300 |
-
{
|
| 301 |
-
Log("OnClientConnected general exception from " + client.IpPort + Environment.NewLine + ex.ToString());
|
| 302 |
-
}
|
| 303 |
-
|
| 304 |
-
WaitForClients();
|
| 305 |
-
}
|
| 306 |
-
|
| 307 |
-
private bool IsAllowedIp(string clientIp)
|
| 308 |
-
{
|
| 309 |
-
if (_PermittedIps != null && _PermittedIps.Count > 0)
|
| 310 |
-
{
|
| 311 |
-
if (!_PermittedIps.Contains(clientIp))
|
| 312 |
-
{
|
| 313 |
-
return false;
|
| 314 |
-
}
|
| 315 |
-
}
|
| 316 |
-
|
| 317 |
-
return true;
|
| 318 |
-
}
|
| 319 |
-
|
| 320 |
-
private void FinaliseConnection(ClientMetadata client)
|
| 321 |
-
{
|
| 322 |
-
Task unawaited = Task.Run(() =>
|
| 323 |
-
{
|
| 324 |
-
#region Add-to-Client-List
|
| 325 |
-
|
| 326 |
-
if (!AddClient(client))
|
| 327 |
-
{
|
| 328 |
-
Log("*** FinaliseConnection unable to add client " + client.IpPort);
|
| 329 |
-
client.TcpClient.Close();
|
| 330 |
-
return;
|
| 331 |
-
}
|
| 332 |
-
|
| 333 |
-
// Do not decrement in this block, decrement is done by the connection reader
|
| 334 |
-
_ActiveClients++;
|
| 335 |
-
|
| 336 |
-
#endregion
|
| 337 |
-
|
| 338 |
-
#region Start-Data-Receiver
|
| 339 |
-
|
| 340 |
-
CancellationToken dataReceiverToken = default(CancellationToken);
|
| 341 |
-
|
| 342 |
-
Log("FinaliseConnection starting data receiver for " + client.IpPort + " (now " + _ActiveClients + " clients)");
|
| 343 |
-
if (_ClientConnected != null)
|
| 344 |
-
{
|
| 345 |
-
Task.Run(() => _ClientConnected(client.IpPort));
|
| 346 |
-
}
|
| 347 |
-
|
| 348 |
-
Task.Run(async () => await DataReceiver(client, dataReceiverToken), dataReceiverToken);
|
| 349 |
-
|
| 350 |
-
#endregion
|
| 351 |
-
|
| 352 |
-
}, _Token);
|
| 353 |
-
}
|
| 354 |
-
|
| 355 |
-
private bool IsConnected(ClientMetadata client)
|
| 356 |
-
{
|
| 357 |
-
if (client.TcpClient.Connected)
|
| 358 |
-
{
|
| 359 |
-
if ((client.TcpClient.Client.Poll(0, SelectMode.SelectWrite)) && (!client.TcpClient.Client.Poll(0, SelectMode.SelectError)))
|
| 360 |
-
{
|
| 361 |
-
byte[] buffer = new byte[1];
|
| 362 |
-
if (client.TcpClient.Client.Receive(buffer, SocketFlags.Peek) == 0)
|
| 363 |
-
{
|
| 364 |
-
return false;
|
| 365 |
-
}
|
| 366 |
-
else
|
| 367 |
-
{
|
| 368 |
-
return true;
|
| 369 |
-
}
|
| 370 |
-
}
|
| 371 |
-
else
|
| 372 |
-
{
|
| 373 |
-
return false;
|
| 374 |
-
}
|
| 375 |
-
}
|
| 376 |
-
else
|
| 377 |
-
{
|
| 378 |
-
return false;
|
| 379 |
-
}
|
| 380 |
-
}
|
| 381 |
-
|
| 382 |
-
private async Task DataReceiver(ClientMetadata client, CancellationToken? cancelToken=null)
|
| 383 |
-
{
|
| 384 |
-
try
|
| 385 |
-
{
|
| 386 |
-
#region Wait-for-Data
|
| 387 |
-
|
| 388 |
-
while (true)
|
| 389 |
-
{
|
| 390 |
-
cancelToken?.ThrowIfCancellationRequested();
|
| 391 |
-
|
| 392 |
-
try
|
| 393 |
-
{
|
| 394 |
-
if (!IsConnected(client)) break;
|
| 395 |
-
|
| 396 |
-
byte[] data = await MessageReadAsync(client);
|
| 397 |
-
if (data == null)
|
| 398 |
-
{
|
| 399 |
-
// no message available
|
| 400 |
-
await Task.Delay(30);
|
| 401 |
-
continue;
|
| 402 |
-
}
|
| 403 |
-
|
| 404 |
-
if (_MessageReceived != null)
|
| 405 |
-
{
|
| 406 |
-
Task<bool> unawaited = Task.Run(() => _MessageReceived(client.IpPort, data));
|
| 407 |
-
}
|
| 408 |
-
}
|
| 409 |
-
catch (Exception)
|
| 410 |
-
{
|
| 411 |
-
break;
|
| 412 |
-
}
|
| 413 |
-
}
|
| 414 |
-
|
| 415 |
-
#endregion
|
| 416 |
-
}
|
| 417 |
-
finally
|
| 418 |
-
{
|
| 419 |
-
_ActiveClients--;
|
| 420 |
-
RemoveClient(client);
|
| 421 |
-
if (_ClientDisconnected != null)
|
| 422 |
-
{
|
| 423 |
-
Task<bool> unawaited = Task.Run(() => _ClientDisconnected(client.IpPort));
|
| 424 |
-
}
|
| 425 |
-
Log("DataReceiver client " + client.IpPort + " disconnected (now " + _ActiveClients + " clients active)");
|
| 426 |
-
}
|
| 427 |
-
}
|
| 428 |
-
|
| 429 |
-
private bool AddClient(ClientMetadata client)
|
| 430 |
-
{
|
| 431 |
-
ClientMetadata removedClient;
|
| 432 |
-
if (!_Clients.TryRemove(client.IpPort, out removedClient))
|
| 433 |
-
{
|
| 434 |
-
// do nothing, it probably did not exist anyway
|
| 435 |
-
}
|
| 436 |
-
|
| 437 |
-
_Clients.TryAdd(client.IpPort, client);
|
| 438 |
-
Log("AddClient added client " + client.IpPort);
|
| 439 |
-
return true;
|
| 440 |
-
}
|
| 441 |
-
|
| 442 |
-
private bool RemoveClient(ClientMetadata client)
|
| 443 |
-
{
|
| 444 |
-
ClientMetadata removedClient;
|
| 445 |
-
if (!_Clients.TryRemove(client.IpPort, out removedClient))
|
| 446 |
-
{
|
| 447 |
-
Log("RemoveClient unable to remove client " + client.IpPort);
|
| 448 |
-
return false;
|
| 449 |
-
}
|
| 450 |
-
else
|
| 451 |
-
{
|
| 452 |
-
Log("RemoveClient removed client " + client.IpPort);
|
| 453 |
-
return true;
|
| 454 |
-
}
|
| 455 |
-
}
|
| 456 |
-
|
| 457 |
-
private byte[] MessageRead(ClientMetadata client)
|
| 458 |
-
{
|
| 459 |
-
/*
|
| 460 |
-
*
|
| 461 |
-
* Do not catch exceptions, let them get caught by the data reader
|
| 462 |
-
* to destroy the connection
|
| 463 |
-
*
|
| 464 |
-
*/
|
| 465 |
-
|
| 466 |
-
#region Variables
|
| 467 |
-
|
| 468 |
-
int bytesRead = 0;
|
| 469 |
-
int sleepInterval = 25;
|
| 470 |
-
int maxTimeout = 500;
|
| 471 |
-
int currentTimeout = 0;
|
| 472 |
-
bool timeout = false;
|
| 473 |
-
|
| 474 |
-
byte[] headerBytes;
|
| 475 |
-
string header = "";
|
| 476 |
-
long contentLength;
|
| 477 |
-
byte[] contentBytes;
|
| 478 |
-
|
| 479 |
-
if (!client.NetworkStream.CanRead) return null;
|
| 480 |
-
if (!client.NetworkStream.DataAvailable) return null;
|
| 481 |
-
|
| 482 |
-
#endregion
|
| 483 |
-
|
| 484 |
-
#region Read-Header
|
| 485 |
-
|
| 486 |
-
using (MemoryStream headerMs = new MemoryStream())
|
| 487 |
-
{
|
| 488 |
-
#region Read-Header-Bytes
|
| 489 |
-
|
| 490 |
-
byte[] headerBuffer = new byte[1];
|
| 491 |
-
timeout = false;
|
| 492 |
-
currentTimeout = 0;
|
| 493 |
-
int read = 0;
|
| 494 |
-
|
| 495 |
-
while ((read = client.NetworkStream.ReadAsync(headerBuffer, 0, headerBuffer.Length).Result) > 0)
|
| 496 |
-
{
|
| 497 |
-
if (read > 0)
|
| 498 |
-
{
|
| 499 |
-
headerMs.Write(headerBuffer, 0, read);
|
| 500 |
-
bytesRead += read;
|
| 501 |
-
|
| 502 |
-
if (bytesRead > 1)
|
| 503 |
-
{
|
| 504 |
-
// check if end of headers reached
|
| 505 |
-
if ((int)headerBuffer[0] == 58) break;
|
| 506 |
-
}
|
| 507 |
-
}
|
| 508 |
-
else
|
| 509 |
-
{
|
| 510 |
-
if (currentTimeout >= maxTimeout)
|
| 511 |
-
{
|
| 512 |
-
timeout = true;
|
| 513 |
-
break;
|
| 514 |
-
}
|
| 515 |
-
else
|
| 516 |
-
{
|
| 517 |
-
currentTimeout += sleepInterval;
|
| 518 |
-
Task.Delay(sleepInterval).Wait();
|
| 519 |
-
}
|
| 520 |
-
}
|
| 521 |
-
}
|
| 522 |
-
|
| 523 |
-
if (timeout)
|
| 524 |
-
{
|
| 525 |
-
Log("*** MessageRead timeout " + currentTimeout + "ms/" + maxTimeout + "ms exceeded while reading header after reading " + bytesRead + " bytes");
|
| 526 |
-
return null;
|
| 527 |
-
}
|
| 528 |
-
|
| 529 |
-
headerBytes = headerMs.ToArray();
|
| 530 |
-
if (headerBytes == null || headerBytes.Length < 1)
|
| 531 |
-
{
|
| 532 |
-
return null;
|
| 533 |
-
}
|
| 534 |
-
|
| 535 |
-
#endregion
|
| 536 |
-
|
| 537 |
-
#region Process-Header
|
| 538 |
-
|
| 539 |
-
header = Encoding.UTF8.GetString(headerBytes);
|
| 540 |
-
header = header.Replace(":", "");
|
| 541 |
-
|
| 542 |
-
if (!Int64.TryParse(header, out contentLength))
|
| 543 |
-
{
|
| 544 |
-
Log("*** MessageRead malformed message from " + client.IpPort + " (message header not an integer)");
|
| 545 |
-
return null;
|
| 546 |
-
}
|
| 547 |
-
|
| 548 |
-
#endregion
|
| 549 |
-
}
|
| 550 |
-
|
| 551 |
-
#endregion
|
| 552 |
-
|
| 553 |
-
#region Read-Data
|
| 554 |
-
|
| 555 |
-
using (MemoryStream dataMs = new MemoryStream())
|
| 556 |
-
{
|
| 557 |
-
long bytesRemaining = contentLength;
|
| 558 |
-
timeout = false;
|
| 559 |
-
currentTimeout = 0;
|
| 560 |
-
|
| 561 |
-
int read = 0;
|
| 562 |
-
byte[] buffer;
|
| 563 |
-
long bufferSize = 2048;
|
| 564 |
-
if (bufferSize > bytesRemaining) bufferSize = bytesRemaining;
|
| 565 |
-
buffer = new byte[bufferSize];
|
| 566 |
-
|
| 567 |
-
while ((read = client.NetworkStream.ReadAsync(buffer, 0, buffer.Length).Result) > 0)
|
| 568 |
-
{
|
| 569 |
-
if (read > 0)
|
| 570 |
-
{
|
| 571 |
-
dataMs.Write(buffer, 0, read);
|
| 572 |
-
bytesRead = bytesRead + read;
|
| 573 |
-
bytesRemaining = bytesRemaining - read;
|
| 574 |
-
currentTimeout = 0;
|
| 575 |
-
|
| 576 |
-
// reduce buffer size if number of bytes remaining is
|
| 577 |
-
// less than the pre-defined buffer size of 2KB
|
| 578 |
-
if (bytesRemaining < bufferSize)
|
| 579 |
-
{
|
| 580 |
-
bufferSize = bytesRemaining;
|
| 581 |
-
// Console.WriteLine("Adjusting buffer size to " + bytesRemaining);
|
| 582 |
-
}
|
| 583 |
-
|
| 584 |
-
buffer = new byte[bufferSize];
|
| 585 |
-
|
| 586 |
-
// check if read fully
|
| 587 |
-
if (bytesRemaining == 0) break;
|
| 588 |
-
if (bytesRead == contentLength) break;
|
| 589 |
-
}
|
| 590 |
-
else
|
| 591 |
-
{
|
| 592 |
-
if (currentTimeout >= maxTimeout)
|
| 593 |
-
{
|
| 594 |
-
timeout = true;
|
| 595 |
-
break;
|
| 596 |
-
}
|
| 597 |
-
else
|
| 598 |
-
{
|
| 599 |
-
currentTimeout += sleepInterval;
|
| 600 |
-
Task.Delay(sleepInterval).Wait();
|
| 601 |
-
}
|
| 602 |
-
}
|
| 603 |
-
}
|
| 604 |
-
|
| 605 |
-
if (timeout)
|
| 606 |
-
{
|
| 607 |
-
Log("*** MessageRead timeout " + currentTimeout + "ms/" + maxTimeout + "ms exceeded while reading content after reading " + bytesRead + " bytes");
|
| 608 |
-
return null;
|
| 609 |
-
}
|
| 610 |
-
|
| 611 |
-
contentBytes = dataMs.ToArray();
|
| 612 |
-
}
|
| 613 |
-
|
| 614 |
-
#endregion
|
| 615 |
-
|
| 616 |
-
#region Check-Content-Bytes
|
| 617 |
-
|
| 618 |
-
if (contentBytes == null || contentBytes.Length < 1)
|
| 619 |
-
{
|
| 620 |
-
Log("*** MessageRead " + client.IpPort + " no content read");
|
| 621 |
-
return null;
|
| 622 |
-
}
|
| 623 |
-
|
| 624 |
-
if (contentBytes.Length != contentLength)
|
| 625 |
-
{
|
| 626 |
-
Log("*** MessageRead " + client.IpPort + " content length " + contentBytes.Length + " bytes does not match header value " + contentLength + ", discarding");
|
| 627 |
-
return null;
|
| 628 |
-
}
|
| 629 |
-
|
| 630 |
-
#endregion
|
| 631 |
-
|
| 632 |
-
return contentBytes;
|
| 633 |
-
}
|
| 634 |
-
|
| 635 |
-
private async Task<byte[]> MessageReadAsync(ClientMetadata client)
|
| 636 |
-
{
|
| 637 |
-
/*
|
| 638 |
-
*
|
| 639 |
-
* Do not catch exceptions, let them get caught by the data reader
|
| 640 |
-
* to destroy the connection
|
| 641 |
-
*
|
| 642 |
-
*/
|
| 643 |
-
|
| 644 |
-
#region Variables
|
| 645 |
-
|
| 646 |
-
int bytesRead = 0;
|
| 647 |
-
int sleepInterval = 25;
|
| 648 |
-
int maxTimeout = 500;
|
| 649 |
-
int currentTimeout = 0;
|
| 650 |
-
bool timeout = false;
|
| 651 |
-
|
| 652 |
-
byte[] headerBytes;
|
| 653 |
-
string header = "";
|
| 654 |
-
long contentLength;
|
| 655 |
-
byte[] contentBytes;
|
| 656 |
-
|
| 657 |
-
if (!client.NetworkStream.CanRead) return null;
|
| 658 |
-
if (!client.NetworkStream.DataAvailable) return null;
|
| 659 |
-
|
| 660 |
-
#endregion
|
| 661 |
-
|
| 662 |
-
#region Read-Header
|
| 663 |
-
|
| 664 |
-
using (MemoryStream headerMs = new MemoryStream())
|
| 665 |
-
{
|
| 666 |
-
#region Read-Header-Bytes
|
| 667 |
-
|
| 668 |
-
byte[] headerBuffer = new byte[1];
|
| 669 |
-
timeout = false;
|
| 670 |
-
currentTimeout = 0;
|
| 671 |
-
int read = 0;
|
| 672 |
-
|
| 673 |
-
while ((read = await client.NetworkStream.ReadAsync(headerBuffer, 0, headerBuffer.Length)) > 0)
|
| 674 |
-
{
|
| 675 |
-
if (read > 0)
|
| 676 |
-
{
|
| 677 |
-
await headerMs.WriteAsync(headerBuffer, 0, read);
|
| 678 |
-
bytesRead += read;
|
| 679 |
-
currentTimeout = 0;
|
| 680 |
-
|
| 681 |
-
if (bytesRead > 1)
|
| 682 |
-
{
|
| 683 |
-
if ((int)headerBuffer[0] == 58) break;
|
| 684 |
-
}
|
| 685 |
-
}
|
| 686 |
-
else
|
| 687 |
-
{
|
| 688 |
-
if (currentTimeout >= maxTimeout)
|
| 689 |
-
{
|
| 690 |
-
timeout = true;
|
| 691 |
-
break;
|
| 692 |
-
}
|
| 693 |
-
else
|
| 694 |
-
{
|
| 695 |
-
currentTimeout += sleepInterval;
|
| 696 |
-
await Task.Delay(sleepInterval);
|
| 697 |
-
}
|
| 698 |
-
}
|
| 699 |
-
}
|
| 700 |
-
|
| 701 |
-
if (timeout)
|
| 702 |
-
{
|
| 703 |
-
Log("*** MessageReadAsync timeout " + currentTimeout + "ms/" + maxTimeout + "ms exceeded while reading header after reading " + bytesRead + " bytes");
|
| 704 |
-
return null;
|
| 705 |
-
}
|
| 706 |
-
|
| 707 |
-
headerBytes = headerMs.ToArray();
|
| 708 |
-
if (headerBytes == null || headerBytes.Length < 1) return null;
|
| 709 |
-
|
| 710 |
-
#endregion
|
| 711 |
-
|
| 712 |
-
#region Process-Header
|
| 713 |
-
|
| 714 |
-
header = Encoding.UTF8.GetString(headerBytes);
|
| 715 |
-
header = header.Replace(":", "");
|
| 716 |
-
|
| 717 |
-
if (!Int64.TryParse(header, out contentLength))
|
| 718 |
-
{
|
| 719 |
-
Log("*** MessageReadAsync malformed message from " + client.IpPort + " (message header not an integer)");
|
| 720 |
-
return null;
|
| 721 |
-
}
|
| 722 |
-
|
| 723 |
-
#endregion
|
| 724 |
-
}
|
| 725 |
-
|
| 726 |
-
#endregion
|
| 727 |
-
|
| 728 |
-
#region Read-Data
|
| 729 |
-
|
| 730 |
-
using (MemoryStream dataMs = new MemoryStream())
|
| 731 |
-
{
|
| 732 |
-
long bytesRemaining = contentLength;
|
| 733 |
-
timeout = false;
|
| 734 |
-
currentTimeout = 0;
|
| 735 |
-
|
| 736 |
-
int read = 0;
|
| 737 |
-
byte[] buffer;
|
| 738 |
-
long bufferSize = 2048;
|
| 739 |
-
if (bufferSize > bytesRemaining) bufferSize = bytesRemaining;
|
| 740 |
-
buffer = new byte[bufferSize];
|
| 741 |
-
|
| 742 |
-
while ((read = await client.NetworkStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
|
| 743 |
-
{
|
| 744 |
-
if (read > 0)
|
| 745 |
-
{
|
| 746 |
-
dataMs.Write(buffer, 0, read);
|
| 747 |
-
bytesRead = bytesRead + read;
|
| 748 |
-
bytesRemaining = bytesRemaining - read;
|
| 749 |
-
currentTimeout = 0;
|
| 750 |
-
|
| 751 |
-
// reduce buffer size if number of bytes remaining is
|
| 752 |
-
// less than the pre-defined buffer size of 2KB
|
| 753 |
-
if (bytesRemaining < bufferSize) bufferSize = bytesRemaining;
|
| 754 |
-
buffer = new byte[bufferSize];
|
| 755 |
-
|
| 756 |
-
// check if read fully
|
| 757 |
-
if (bytesRemaining == 0) break;
|
| 758 |
-
if (bytesRead == contentLength) break;
|
| 759 |
-
}
|
| 760 |
-
|
| 761 |
-
if (!client.NetworkStream.DataAvailable)
|
| 762 |
-
{
|
| 763 |
-
while (true)
|
| 764 |
-
{
|
| 765 |
-
if (currentTimeout >= maxTimeout)
|
| 766 |
-
{
|
| 767 |
-
timeout = true;
|
| 768 |
-
break;
|
| 769 |
-
}
|
| 770 |
-
else
|
| 771 |
-
{
|
| 772 |
-
currentTimeout += sleepInterval;
|
| 773 |
-
await Task.Delay(sleepInterval);
|
| 774 |
-
}
|
| 775 |
-
}
|
| 776 |
-
|
| 777 |
-
if (timeout) break;
|
| 778 |
-
}
|
| 779 |
-
}
|
| 780 |
-
|
| 781 |
-
if (timeout)
|
| 782 |
-
{
|
| 783 |
-
Log("*** MessageReadAsync timeout " + currentTimeout + "ms/" + maxTimeout + "ms exceeded while reading content after reading " + bytesRead + " bytes");
|
| 784 |
-
return null;
|
| 785 |
-
}
|
| 786 |
-
|
| 787 |
-
contentBytes = dataMs.ToArray();
|
| 788 |
-
}
|
| 789 |
-
|
| 790 |
-
#endregion
|
| 791 |
-
|
| 792 |
-
#region Check-Content-Bytes
|
| 793 |
-
|
| 794 |
-
if (contentBytes == null || contentBytes.Length < 1)
|
| 795 |
-
{
|
| 796 |
-
Log("*** MessageReadAsync " + client.IpPort + " no content read");
|
| 797 |
-
return null;
|
| 798 |
-
}
|
| 799 |
-
|
| 800 |
-
if (contentBytes.Length != contentLength)
|
| 801 |
-
{
|
| 802 |
-
Log("*** MessageReadAsync " + client.IpPort + " content length " + contentBytes.Length + " bytes does not match header value " + contentLength + ", discarding");
|
| 803 |
-
return null;
|
| 804 |
-
}
|
| 805 |
-
|
| 806 |
-
#endregion
|
| 807 |
-
|
| 808 |
-
return contentBytes;
|
| 809 |
-
}
|
| 810 |
-
|
| 811 |
-
private bool MessageWrite(ClientMetadata client, byte[] data)
|
| 812 |
-
{
|
| 813 |
-
try
|
| 814 |
-
{
|
| 815 |
-
#region Format-Message
|
| 816 |
-
|
| 817 |
-
string header = "";
|
| 818 |
-
byte[] headerBytes;
|
| 819 |
-
byte[] message;
|
| 820 |
-
|
| 821 |
-
if (data == null || data.Length < 1) header += "0:";
|
| 822 |
-
else header += data.Length + ":";
|
| 823 |
-
|
| 824 |
-
headerBytes = Encoding.UTF8.GetBytes(header);
|
| 825 |
-
int messageLen = headerBytes.Length;
|
| 826 |
-
if (data != null && data.Length > 0) messageLen += data.Length;
|
| 827 |
-
|
| 828 |
-
message = new byte[messageLen];
|
| 829 |
-
Buffer.BlockCopy(headerBytes, 0, message, 0, headerBytes.Length);
|
| 830 |
-
|
| 831 |
-
if (data != null && data.Length > 0) Buffer.BlockCopy(data, 0, message, headerBytes.Length, data.Length);
|
| 832 |
-
|
| 833 |
-
#endregion
|
| 834 |
-
|
| 835 |
-
#region Send-Message
|
| 836 |
-
|
| 837 |
-
client.NetworkStream.Write(message, 0, message.Length);
|
| 838 |
-
client.NetworkStream.Flush();
|
| 839 |
-
return true;
|
| 840 |
-
|
| 841 |
-
#endregion
|
| 842 |
-
}
|
| 843 |
-
catch (Exception)
|
| 844 |
-
{
|
| 845 |
-
Log("*** MessageWrite " + client.IpPort + " disconnected due to exception");
|
| 846 |
-
return false;
|
| 847 |
-
}
|
| 848 |
-
}
|
| 849 |
-
|
| 850 |
-
private async Task<bool> MessageWriteAsync(ClientMetadata client, byte[] data)
|
| 851 |
-
{
|
| 852 |
-
try
|
| 853 |
-
{
|
| 854 |
-
#region Format-Message
|
| 855 |
-
|
| 856 |
-
string header = "";
|
| 857 |
-
byte[] headerBytes;
|
| 858 |
-
byte[] message;
|
| 859 |
-
|
| 860 |
-
if (data == null || data.Length < 1) header += "0:";
|
| 861 |
-
else header += data.Length + ":";
|
| 862 |
-
|
| 863 |
-
headerBytes = Encoding.UTF8.GetBytes(header);
|
| 864 |
-
int messageLen = headerBytes.Length;
|
| 865 |
-
if (data != null && data.Length > 0) messageLen += data.Length;
|
| 866 |
-
|
| 867 |
-
message = new byte[messageLen];
|
| 868 |
-
Buffer.BlockCopy(headerBytes, 0, message, 0, headerBytes.Length);
|
| 869 |
-
|
| 870 |
-
if (data != null && data.Length > 0) Buffer.BlockCopy(data, 0, message, headerBytes.Length, data.Length);
|
| 871 |
-
|
| 872 |
-
#endregion
|
| 873 |
-
|
| 874 |
-
#region Send-Message-Async
|
| 875 |
-
|
| 876 |
-
await client.NetworkStream.WriteAsync(message, 0, message.Length);
|
| 877 |
-
await client.NetworkStream.FlushAsync();
|
| 878 |
-
return true;
|
| 879 |
-
|
| 880 |
-
#endregion
|
| 881 |
-
}
|
| 882 |
-
catch (Exception)
|
| 883 |
-
{
|
| 884 |
-
Log("*** MessageWriteAsync " + client.IpPort + " disconnected due to exception");
|
| 885 |
-
return false;
|
| 886 |
-
}
|
| 887 |
-
}
|
| 888 |
-
|
| 889 |
-
#endregion
|
| 890 |
-
}
|
| 891 |
-
}
|
| 892 |
-
|
| 893 |
-
```
|
| 894 |
-
|
| 895 |
-
### Bug Type:
|
| 896 |
-
NULL_DEREFERENCE
|
| 897 |
-
|
| 898 |
-
### Qualifier:
|
| 899 |
-
pointer `client` last assigned on line 262 could be null and is dereferenced at line 283, column 17.
|
| 900 |
-
|
| 901 |
-
### Severity:
|
| 902 |
-
ERROR
|
| 903 |
-
|
| 904 |
-
### Procedure:
|
| 905 |
-
Void WatsonTcpServer.OnClientConnected(IAsyncResult)
|
| 906 |
-
|
| 907 |
-
### File:
|
| 908 |
-
WatsonTcp/WatsonTcpServer.cs
|
| 909 |
-
|
| 910 |
-
### Key:
|
| 911 |
-
WatsonTcpServer.cs|OnClientConnected|NULL_DEREFERENCE
|
| 912 |
-
|
| 913 |
-
### Node Key:
|
| 914 |
-
ac80bb13c2683cc55f55666d57b4dcc3
|
| 915 |
-
|
| 916 |
-
### Hash:
|
| 917 |
-
beb56e54c31ad0406c564e7344fef944
|
| 918 |
-
|
| 919 |
-
### Bug Type Hum:
|
| 920 |
-
Null Dereference
|
| 921 |
-
|
| 922 |
-
## Task
|
| 923 |
-
|
| 924 |
-
Fix the bug in the code.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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0003/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0003/instruction.md
DELETED
|
@@ -1,171 +0,0 @@
|
|
| 1 |
-
# InferredBugs Task - Csharp
|
| 2 |
-
|
| 3 |
-
## Project Information
|
| 4 |
-
|
| 5 |
-
**Project:** WatsonTcp
|
| 6 |
-
**Bug ID:** 2
|
| 7 |
-
**Language:** csharp
|
| 8 |
-
|
| 9 |
-
## Bug Information
|
| 10 |
-
|
| 11 |
-
### File-Level Changes:
|
| 12 |
-
|
| 13 |
-
**Before (Buggy File):**
|
| 14 |
-
```csharp
|
| 15 |
-
using System;
|
| 16 |
-
using System.Collections.Generic;
|
| 17 |
-
using System.Text;
|
| 18 |
-
using System.Threading.Tasks;
|
| 19 |
-
using Newtonsoft.Json;
|
| 20 |
-
using WatsonTcp;
|
| 21 |
-
|
| 22 |
-
namespace Test.Metadata
|
| 23 |
-
{
|
| 24 |
-
class Program
|
| 25 |
-
{
|
| 26 |
-
static void Main(string[] args)
|
| 27 |
-
{
|
| 28 |
-
using (WatsonTcpServer server = new WatsonTcpServer("127.0.0.1", 8000))
|
| 29 |
-
{
|
| 30 |
-
server.Events.MessageReceived += ServerMessageReceived;
|
| 31 |
-
server.Start();
|
| 32 |
-
Task.Delay(1000).Wait();
|
| 33 |
-
using (WatsonTcpClient client = new WatsonTcpClient("127.0.0.1", 8000))
|
| 34 |
-
{
|
| 35 |
-
client.Events.MessageReceived += ClientMessageReceived;
|
| 36 |
-
client.Connect();
|
| 37 |
-
|
| 38 |
-
for (int i = 0; i < 10; i++)
|
| 39 |
-
{
|
| 40 |
-
Person p = new Person("hello", "world", i);
|
| 41 |
-
Dictionary<object, object> md = new Dictionary<object, object>();
|
| 42 |
-
md.Add("person", p);
|
| 43 |
-
client.Send(("Message " + i), md);
|
| 44 |
-
Task.Delay(1000).Wait();
|
| 45 |
-
}
|
| 46 |
-
}
|
| 47 |
-
}
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
#region Events
|
| 51 |
-
|
| 52 |
-
private static void ServerMessageReceived(object sender, MessageReceivedEventArgs args)
|
| 53 |
-
{
|
| 54 |
-
try
|
| 55 |
-
{
|
| 56 |
-
object o = args.Metadata["person"];
|
| 57 |
-
Console.WriteLine(SerializeJson(o, true));
|
| 58 |
-
Person p = (Person)o;
|
| 59 |
-
Console.WriteLine(p.FirstName + " " + p.LastName + ": " + p.Number);
|
| 60 |
-
}
|
| 61 |
-
catch (Exception e)
|
| 62 |
-
{
|
| 63 |
-
Console.WriteLine(e.ToString());
|
| 64 |
-
}
|
| 65 |
-
}
|
| 66 |
-
|
| 67 |
-
private static void ClientMessageReceived(object sender, MessageReceivedEventArgs args)
|
| 68 |
-
{
|
| 69 |
-
|
| 70 |
-
}
|
| 71 |
-
|
| 72 |
-
#endregion
|
| 73 |
-
|
| 74 |
-
#region Serialization
|
| 75 |
-
|
| 76 |
-
private static readonly JsonSerializerSettings HardenedSerializerSettings = new JsonSerializerSettings
|
| 77 |
-
{
|
| 78 |
-
TypeNameHandling = TypeNameHandling.None // Prevents CS2328 style attacks if a project is allowing automatic type resolution elsewhere.
|
| 79 |
-
};
|
| 80 |
-
|
| 81 |
-
private static readonly JsonSerializerSettings SerializerDefaults = new JsonSerializerSettings
|
| 82 |
-
{
|
| 83 |
-
NullValueHandling = NullValueHandling.Ignore,
|
| 84 |
-
DateTimeZoneHandling = DateTimeZoneHandling.Local,
|
| 85 |
-
};
|
| 86 |
-
|
| 87 |
-
internal static T DeserializeJson<T>(string json)
|
| 88 |
-
{
|
| 89 |
-
if (String.IsNullOrEmpty(json)) throw new ArgumentNullException(nameof(json));
|
| 90 |
-
return JsonConvert.DeserializeObject<T>(json, HardenedSerializerSettings);
|
| 91 |
-
}
|
| 92 |
-
|
| 93 |
-
internal static string SerializeJson(object obj, bool pretty)
|
| 94 |
-
{
|
| 95 |
-
if (obj == null) return null;
|
| 96 |
-
string json;
|
| 97 |
-
|
| 98 |
-
if (pretty)
|
| 99 |
-
{
|
| 100 |
-
json = JsonConvert.SerializeObject(
|
| 101 |
-
obj,
|
| 102 |
-
Newtonsoft.Json.Formatting.Indented,
|
| 103 |
-
SerializerDefaults
|
| 104 |
-
);
|
| 105 |
-
}
|
| 106 |
-
else
|
| 107 |
-
{
|
| 108 |
-
json = JsonConvert.SerializeObject(
|
| 109 |
-
obj,
|
| 110 |
-
SerializerDefaults
|
| 111 |
-
);
|
| 112 |
-
}
|
| 113 |
-
|
| 114 |
-
return json;
|
| 115 |
-
}
|
| 116 |
-
|
| 117 |
-
#endregion
|
| 118 |
-
}
|
| 119 |
-
|
| 120 |
-
public class Person
|
| 121 |
-
{
|
| 122 |
-
public string FirstName { get; set; }
|
| 123 |
-
public string LastName { get; set; }
|
| 124 |
-
public int Number { get; set; }
|
| 125 |
-
|
| 126 |
-
public Person()
|
| 127 |
-
{
|
| 128 |
-
|
| 129 |
-
}
|
| 130 |
-
|
| 131 |
-
public Person(string first, string last, int num)
|
| 132 |
-
{
|
| 133 |
-
FirstName = first;
|
| 134 |
-
LastName = last;
|
| 135 |
-
Number = num;
|
| 136 |
-
}
|
| 137 |
-
}
|
| 138 |
-
}
|
| 139 |
-
|
| 140 |
-
```
|
| 141 |
-
|
| 142 |
-
### Bug Type:
|
| 143 |
-
NULL_DEREFERENCE
|
| 144 |
-
|
| 145 |
-
### Qualifier:
|
| 146 |
-
pointer `p` last assigned on line 44 could be null and is dereferenced at line 45, column 17.
|
| 147 |
-
|
| 148 |
-
### Severity:
|
| 149 |
-
ERROR
|
| 150 |
-
|
| 151 |
-
### Procedure:
|
| 152 |
-
Void Program.ServerMessageReceived(Object,MessageReceivedEventArgs)
|
| 153 |
-
|
| 154 |
-
### File:
|
| 155 |
-
Test.Metadata/Program.cs
|
| 156 |
-
|
| 157 |
-
### Key:
|
| 158 |
-
Program.cs|ServerMessageReceived|NULL_DEREFERENCE
|
| 159 |
-
|
| 160 |
-
### Node Key:
|
| 161 |
-
8f0b64b688088fc912286553425a9fd2
|
| 162 |
-
|
| 163 |
-
### Hash:
|
| 164 |
-
58a2424dbf0bc7993ac822ac39ac6063
|
| 165 |
-
|
| 166 |
-
### Bug Type Hum:
|
| 167 |
-
Null Dereference
|
| 168 |
-
|
| 169 |
-
## Task
|
| 170 |
-
|
| 171 |
-
Fix the bug in the code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0004/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0004/instruction.md
DELETED
|
@@ -1,133 +0,0 @@
|
|
| 1 |
-
# InferredBugs Task - Csharp
|
| 2 |
-
|
| 3 |
-
## Project Information
|
| 4 |
-
|
| 5 |
-
**Project:** dotnet-cas-client
|
| 6 |
-
**Bug ID:** 1
|
| 7 |
-
**Language:** csharp
|
| 8 |
-
|
| 9 |
-
## Bug Information
|
| 10 |
-
|
| 11 |
-
### File-Level Changes:
|
| 12 |
-
|
| 13 |
-
**Before (Buggy File):**
|
| 14 |
-
```csharp
|
| 15 |
-
/*
|
| 16 |
-
* Licensed to Apereo under one or more contributor license
|
| 17 |
-
* agreements. See the NOTICE file distributed with this work
|
| 18 |
-
* for additional information regarding copyright ownership.
|
| 19 |
-
* Apereo licenses this file to you under the Apache License,
|
| 20 |
-
* Version 2.0 (the "License"); you may not use this file
|
| 21 |
-
* except in compliance with the License. You may obtain a
|
| 22 |
-
* copy of the License at:
|
| 23 |
-
*
|
| 24 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 25 |
-
*
|
| 26 |
-
* Unless required by applicable law or agreed to in writing,
|
| 27 |
-
* software distributed under the License is distributed on
|
| 28 |
-
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 29 |
-
* KIND, either express or implied. See the License for the
|
| 30 |
-
* specific language governing permissions and limitations
|
| 31 |
-
* under the License.
|
| 32 |
-
*/
|
| 33 |
-
|
| 34 |
-
using System.IO;
|
| 35 |
-
using DotNetCasClient.Security;
|
| 36 |
-
|
| 37 |
-
namespace DotNetCasClient.Validation.TicketValidator
|
| 38 |
-
{
|
| 39 |
-
/// <summary>
|
| 40 |
-
/// CAS 1.0 Ticket Validator
|
| 41 |
-
/// </summary>
|
| 42 |
-
/// <remarks>
|
| 43 |
-
/// This is the .Net port of org.jasig.cas.client.validation.Cas10TicketValidator
|
| 44 |
-
/// </remarks>
|
| 45 |
-
/// <author>Scott Battaglia</author>
|
| 46 |
-
/// <author>William G. Thompson, Jr. (.Net)</author>
|
| 47 |
-
/// <author>Marvin S. Addison</author>
|
| 48 |
-
/// <author>Scott Holodak (.Net)</author>
|
| 49 |
-
class Cas10TicketValidator : AbstractCasProtocolTicketValidator
|
| 50 |
-
{
|
| 51 |
-
#region Properties
|
| 52 |
-
/// <summary>
|
| 53 |
-
/// The endpoint of the validation URL. Should be relative (i.e. not start with a "/").
|
| 54 |
-
/// i.e. validate or serviceValidate.
|
| 55 |
-
/// </summary>
|
| 56 |
-
public override string UrlSuffix
|
| 57 |
-
{
|
| 58 |
-
get
|
| 59 |
-
{
|
| 60 |
-
return "validate";
|
| 61 |
-
}
|
| 62 |
-
}
|
| 63 |
-
#endregion
|
| 64 |
-
|
| 65 |
-
#region Methods
|
| 66 |
-
/// <summary>
|
| 67 |
-
/// Performs Cas10TicketValidator initialization.
|
| 68 |
-
/// </summary>
|
| 69 |
-
public override void Initialize() { /* Do nothing */ }
|
| 70 |
-
|
| 71 |
-
/// <summary>
|
| 72 |
-
/// Parses the response from the server into a CAS Assertion and includes this in
|
| 73 |
-
/// a CASPrincipal.
|
| 74 |
-
/// </summary>
|
| 75 |
-
/// <param name="response">the response from the server, in any format.</param>
|
| 76 |
-
/// <param name="ticket">The ticket used to generate the validation response</param>
|
| 77 |
-
/// <returns>
|
| 78 |
-
/// a Principal backed by a CAS Assertion, if one could be created from the response.
|
| 79 |
-
/// </returns>
|
| 80 |
-
/// <exception cref="TicketValidationException">
|
| 81 |
-
/// Thrown if creation of the Assertion fails.
|
| 82 |
-
/// </exception>
|
| 83 |
-
protected override ICasPrincipal ParseResponseFromServer(string response, string ticket)
|
| 84 |
-
{
|
| 85 |
-
if (response == null || !response.StartsWith("yes"))
|
| 86 |
-
{
|
| 87 |
-
throw new TicketValidationException("CAS Server could not validate ticket.");
|
| 88 |
-
}
|
| 89 |
-
|
| 90 |
-
try
|
| 91 |
-
{
|
| 92 |
-
StringReader reader = new StringReader(response);
|
| 93 |
-
reader.ReadLine();
|
| 94 |
-
string name = reader.ReadLine();
|
| 95 |
-
return new CasPrincipal(new Assertion(name));
|
| 96 |
-
}
|
| 97 |
-
catch (IOException e)
|
| 98 |
-
{
|
| 99 |
-
throw new TicketValidationException("CAS Server response could not be parsed.", e);
|
| 100 |
-
}
|
| 101 |
-
}
|
| 102 |
-
#endregion
|
| 103 |
-
}
|
| 104 |
-
}
|
| 105 |
-
```
|
| 106 |
-
|
| 107 |
-
### Bug Type:
|
| 108 |
-
DOTNET_RESOURCE_LEAK
|
| 109 |
-
|
| 110 |
-
### Qualifier:
|
| 111 |
-
Leaked resource reader of type System.IO.StringReader in method "ICasPrincipal Cas10TicketValidator.ParseResponseFromServer(String,String)".
|
| 112 |
-
|
| 113 |
-
### Severity:
|
| 114 |
-
ERROR
|
| 115 |
-
|
| 116 |
-
### Procedure:
|
| 117 |
-
ICasPrincipal Cas10TicketValidator.ParseResponseFromServer(String,String)
|
| 118 |
-
|
| 119 |
-
### File:
|
| 120 |
-
DotNetCasClient/Validation/TicketValidator/Cas10TicketValidator.cs
|
| 121 |
-
|
| 122 |
-
### Key:
|
| 123 |
-
Cas10TicketValidator.cs|ParseResponseFromServer|DOTNET_RESOURCE_LEAK
|
| 124 |
-
|
| 125 |
-
### Hash:
|
| 126 |
-
07b7272a868608d91fbcc32d7ff01fef
|
| 127 |
-
|
| 128 |
-
### Bug Type Hum:
|
| 129 |
-
Dotnet Resource Leak
|
| 130 |
-
|
| 131 |
-
## Task
|
| 132 |
-
|
| 133 |
-
Fix the bug in the code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0005/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0005/instruction.md
DELETED
|
@@ -1,235 +0,0 @@
|
|
| 1 |
-
# InferredBugs Task - Csharp
|
| 2 |
-
|
| 3 |
-
## Project Information
|
| 4 |
-
|
| 5 |
-
**Project:** dotnet-cas-client
|
| 6 |
-
**Bug ID:** 2
|
| 7 |
-
**Language:** csharp
|
| 8 |
-
|
| 9 |
-
## Bug Information
|
| 10 |
-
|
| 11 |
-
### File-Level Changes:
|
| 12 |
-
|
| 13 |
-
**Before (Buggy File):**
|
| 14 |
-
```csharp
|
| 15 |
-
/*
|
| 16 |
-
* Licensed to Apereo under one or more contributor license
|
| 17 |
-
* agreements. See the NOTICE file distributed with this work
|
| 18 |
-
* for additional information regarding copyright ownership.
|
| 19 |
-
* Apereo licenses this file to you under the Apache License,
|
| 20 |
-
* Version 2.0 (the "License"); you may not use this file
|
| 21 |
-
* except in compliance with the License. You may obtain a
|
| 22 |
-
* copy of the License at:
|
| 23 |
-
*
|
| 24 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 25 |
-
*
|
| 26 |
-
* Unless required by applicable law or agreed to in writing,
|
| 27 |
-
* software distributed under the License is distributed on
|
| 28 |
-
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 29 |
-
* KIND, either express or implied. See the License for the
|
| 30 |
-
* specific language governing permissions and limitations
|
| 31 |
-
* under the License.
|
| 32 |
-
*/
|
| 33 |
-
|
| 34 |
-
using System;
|
| 35 |
-
using System.Collections.Generic;
|
| 36 |
-
using System.IO;
|
| 37 |
-
using System.Xml;
|
| 38 |
-
using DotNetCasClient.Logging;
|
| 39 |
-
using DotNetCasClient.Security;
|
| 40 |
-
|
| 41 |
-
namespace DotNetCasClient.Validation
|
| 42 |
-
{
|
| 43 |
-
/// <summary>
|
| 44 |
-
/// Represents a CAS SAML 1.1 response from a CAS server, using Xml parsing to
|
| 45 |
-
/// populate the object.
|
| 46 |
-
/// </summary>
|
| 47 |
-
class CasSaml11Response
|
| 48 |
-
{
|
| 49 |
-
#region Fields
|
| 50 |
-
// The SAML 1.1 Assertion namespace
|
| 51 |
-
const string SAML11_ASSERTION_NAMESPACE = "urn:oasis:names:tc:SAML:1.0:assertion";
|
| 52 |
-
|
| 53 |
-
private static readonly Logger protoLogger = new Logger(Category.Protocol);
|
| 54 |
-
|
| 55 |
-
// Tolerance ticks for checking the current time against the SAML
|
| 56 |
-
// Assertion valid times.
|
| 57 |
-
private readonly long _ToleranceTicks = 1000L * TimeSpan.TicksPerMillisecond;
|
| 58 |
-
|
| 59 |
-
// The raw response received from the CAS server
|
| 60 |
-
private readonly string _CasResponse;
|
| 61 |
-
#endregion
|
| 62 |
-
|
| 63 |
-
#region Properties
|
| 64 |
-
/// <summary>
|
| 65 |
-
/// Whether a valid SAML Assertion was found for processing
|
| 66 |
-
/// </summary>
|
| 67 |
-
public bool HasCasSamlAssertion { get; private set; }
|
| 68 |
-
|
| 69 |
-
/// <summary>
|
| 70 |
-
/// The Apereo CAS ICasPrincipal assertion built from the received CAS
|
| 71 |
-
/// SAML 1.1 response
|
| 72 |
-
/// </summary>
|
| 73 |
-
public ICasPrincipal CasPrincipal { get; private set; }
|
| 74 |
-
#endregion
|
| 75 |
-
|
| 76 |
-
#region Constructor
|
| 77 |
-
/// <summary>
|
| 78 |
-
/// Creates a CasSaml11Response from the response returned by the CAS server.
|
| 79 |
-
/// The SAMLAssertion processed is the first valid SAML Asssertion found in
|
| 80 |
-
/// the server response.
|
| 81 |
-
/// </summary>
|
| 82 |
-
/// <param name="response">
|
| 83 |
-
/// the xml for the SAML 1.1 response received in response to the
|
| 84 |
-
/// samlValidate query to the CAS server
|
| 85 |
-
/// </param>
|
| 86 |
-
/// <param name="tolerance">
|
| 87 |
-
/// Tolerance milliseconds for checking the current time against the SAML
|
| 88 |
-
/// Assertion valid times.
|
| 89 |
-
/// </param>
|
| 90 |
-
public CasSaml11Response(string response, long tolerance)
|
| 91 |
-
{
|
| 92 |
-
_ToleranceTicks = tolerance * TimeSpan.TicksPerMillisecond;
|
| 93 |
-
HasCasSamlAssertion = false;
|
| 94 |
-
_CasResponse = response;
|
| 95 |
-
ProcessValidAssertion();
|
| 96 |
-
HasCasSamlAssertion = true;
|
| 97 |
-
}
|
| 98 |
-
#endregion
|
| 99 |
-
|
| 100 |
-
#region Methods
|
| 101 |
-
/// <summary>
|
| 102 |
-
/// Initializes the CAS IAssertion for this instance from the first valid
|
| 103 |
-
/// Assertion node in the CAS server response.
|
| 104 |
-
/// </summary>
|
| 105 |
-
/// <exception cref="TicketValidationException">
|
| 106 |
-
/// Thrown when data problems are encountered parsing
|
| 107 |
-
/// the CAS server response that contains the Assertion, such as
|
| 108 |
-
/// no valid Assertion found or no Authentication statment found in the
|
| 109 |
-
/// the valid Assertion.
|
| 110 |
-
/// </exception>
|
| 111 |
-
private void ProcessValidAssertion()
|
| 112 |
-
{
|
| 113 |
-
protoLogger.Debug("Unmarshalling SAML response");
|
| 114 |
-
XmlDocument document = new XmlDocument();
|
| 115 |
-
document.Load(new StringReader(_CasResponse));
|
| 116 |
-
|
| 117 |
-
XmlNamespaceManager nsmgr = new XmlNamespaceManager(document.NameTable);
|
| 118 |
-
nsmgr.AddNamespace("assertion", SAML11_ASSERTION_NAMESPACE);
|
| 119 |
-
|
| 120 |
-
if (document.DocumentElement != null) {
|
| 121 |
-
XmlNodeList assertions = document.DocumentElement.SelectNodes("descendant::assertion:Assertion", nsmgr);
|
| 122 |
-
|
| 123 |
-
if (assertions == null || assertions.Count < 1)
|
| 124 |
-
{
|
| 125 |
-
protoLogger.Debug("No assertions found in SAML response.");
|
| 126 |
-
throw new TicketValidationException("No assertions found.");
|
| 127 |
-
}
|
| 128 |
-
|
| 129 |
-
XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
|
| 130 |
-
xmlReaderSettings.ConformanceLevel = ConformanceLevel.Auto;
|
| 131 |
-
xmlReaderSettings.IgnoreWhitespace = true;
|
| 132 |
-
xmlReaderSettings.IgnoreComments = true;
|
| 133 |
-
xmlReaderSettings.CloseInput = true;
|
| 134 |
-
|
| 135 |
-
foreach (XmlNode assertionNode in assertions)
|
| 136 |
-
{
|
| 137 |
-
XmlNode conditionsNode = assertionNode.SelectSingleNode("descendant::assertion:Conditions", nsmgr);
|
| 138 |
-
if (conditionsNode == null)
|
| 139 |
-
{
|
| 140 |
-
continue;
|
| 141 |
-
}
|
| 142 |
-
|
| 143 |
-
DateTime notBefore;
|
| 144 |
-
DateTime notOnOrAfter;
|
| 145 |
-
try
|
| 146 |
-
{
|
| 147 |
-
notBefore = SamlUtils.GetAttributeValueAsDateTime(conditionsNode, "NotBefore");
|
| 148 |
-
notOnOrAfter = SamlUtils.GetAttributeValueAsDateTime(conditionsNode, "NotOnOrAfter");
|
| 149 |
-
if (!SamlUtils.IsValidAssertion(notBefore, notOnOrAfter, _ToleranceTicks))
|
| 150 |
-
{
|
| 151 |
-
continue;
|
| 152 |
-
}
|
| 153 |
-
}
|
| 154 |
-
catch (Exception)
|
| 155 |
-
{
|
| 156 |
-
continue;
|
| 157 |
-
}
|
| 158 |
-
|
| 159 |
-
XmlNode authenticationStmtNode = assertionNode.SelectSingleNode("descendant::assertion:AuthenticationStatement", nsmgr);
|
| 160 |
-
if (authenticationStmtNode == null)
|
| 161 |
-
{
|
| 162 |
-
protoLogger.Debug("No AuthenticationStatement found in SAML response.");
|
| 163 |
-
throw new TicketValidationException("No AuthenticationStatement found in the CAS response.");
|
| 164 |
-
}
|
| 165 |
-
|
| 166 |
-
string authMethod = SamlUtils.GetAttributeValue(authenticationStmtNode.Attributes, "AuthenticationMethod");
|
| 167 |
-
|
| 168 |
-
XmlNode nameIdentifierNode = assertionNode.SelectSingleNode("child::assertion:AuthenticationStatement/child::assertion:Subject/child::assertion:NameIdentifier", nsmgr);
|
| 169 |
-
if (nameIdentifierNode == null)
|
| 170 |
-
{
|
| 171 |
-
protoLogger.Debug("No NameIdentifier found in SAML response.");
|
| 172 |
-
throw new TicketValidationException("No NameIdentifier found in AuthenticationStatement of the CAS response.");
|
| 173 |
-
}
|
| 174 |
-
|
| 175 |
-
string subject = nameIdentifierNode.FirstChild.Value;
|
| 176 |
-
|
| 177 |
-
IList<string> authValues = new List<string>();
|
| 178 |
-
IDictionary<string, IList<string>> authenticationAttributes = new Dictionary<string, IList<string>>();
|
| 179 |
-
authValues.Add(authMethod);
|
| 180 |
-
authenticationAttributes.Add("samlAuthenticationStatement::authMethod", authValues);
|
| 181 |
-
|
| 182 |
-
IAssertion casAssertion;
|
| 183 |
-
|
| 184 |
-
XmlNode attributeStmtNode = assertionNode.SelectSingleNode("descendant::assertion:AttributeStatement", nsmgr);
|
| 185 |
-
if (attributeStmtNode != null)
|
| 186 |
-
{
|
| 187 |
-
IDictionary<string, IList<string>> personAttributes = SamlUtils.GetAttributesFor(attributeStmtNode, nsmgr, subject);
|
| 188 |
-
casAssertion = new Assertion(subject, notBefore, notOnOrAfter, personAttributes);
|
| 189 |
-
}
|
| 190 |
-
else
|
| 191 |
-
{
|
| 192 |
-
casAssertion = new Assertion(subject, notBefore, notOnOrAfter);
|
| 193 |
-
}
|
| 194 |
-
|
| 195 |
-
CasPrincipal = new CasPrincipal(casAssertion, null, null);
|
| 196 |
-
|
| 197 |
-
return;
|
| 198 |
-
}
|
| 199 |
-
}
|
| 200 |
-
protoLogger.Debug("No assertions found in SAML response.");
|
| 201 |
-
throw new TicketValidationException("No valid assertions found in the CAS response.");
|
| 202 |
-
}
|
| 203 |
-
#endregion
|
| 204 |
-
}
|
| 205 |
-
}
|
| 206 |
-
|
| 207 |
-
```
|
| 208 |
-
|
| 209 |
-
### Bug Type:
|
| 210 |
-
DOTNET_RESOURCE_LEAK
|
| 211 |
-
|
| 212 |
-
### Qualifier:
|
| 213 |
-
Leaked resource (output of System.IO.StringReader::.ctor() at Line 101) of type System.IO.StringReader in method "Void CasSaml11Response.ProcessValidAssertion()".
|
| 214 |
-
|
| 215 |
-
### Severity:
|
| 216 |
-
ERROR
|
| 217 |
-
|
| 218 |
-
### Procedure:
|
| 219 |
-
Void CasSaml11Response.ProcessValidAssertion()
|
| 220 |
-
|
| 221 |
-
### File:
|
| 222 |
-
DotNetCasClient/Validation/CasSaml11Response.cs
|
| 223 |
-
|
| 224 |
-
### Key:
|
| 225 |
-
CasSaml11Response.cs|ProcessValidAssertion|DOTNET_RESOURCE_LEAK
|
| 226 |
-
|
| 227 |
-
### Hash:
|
| 228 |
-
c4e8e9fb51948ec8a9f3dc2cdf26f1fd
|
| 229 |
-
|
| 230 |
-
### Bug Type Hum:
|
| 231 |
-
Dotnet Resource Leak
|
| 232 |
-
|
| 233 |
-
## Task
|
| 234 |
-
|
| 235 |
-
Fix the bug in the code.
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0006/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0006/instruction.md
DELETED
|
@@ -1,977 +0,0 @@
|
|
| 1 |
-
# InferredBugs Task - Csharp
|
| 2 |
-
|
| 3 |
-
## Project Information
|
| 4 |
-
|
| 5 |
-
**Project:** Sylvan
|
| 6 |
-
**Bug ID:** 1
|
| 7 |
-
**Language:** csharp
|
| 8 |
-
|
| 9 |
-
## Bug Information
|
| 10 |
-
|
| 11 |
-
### File-Level Changes:
|
| 12 |
-
|
| 13 |
-
**Before (Buggy File):**
|
| 14 |
-
```csharp
|
| 15 |
-
using Sylvan.Benchmarks;
|
| 16 |
-
using System;
|
| 17 |
-
using System.Collections.Generic;
|
| 18 |
-
using System.Data;
|
| 19 |
-
using System.Data.Common;
|
| 20 |
-
using System.Globalization;
|
| 21 |
-
using System.IO;
|
| 22 |
-
using System.Linq;
|
| 23 |
-
using System.Text;
|
| 24 |
-
using System.Threading.Tasks;
|
| 25 |
-
using Xunit;
|
| 26 |
-
|
| 27 |
-
namespace Sylvan.Data.Csv
|
| 28 |
-
{
|
| 29 |
-
public class CsvDataReaderTests
|
| 30 |
-
{
|
| 31 |
-
[Fact]
|
| 32 |
-
public void SylvanBench()
|
| 33 |
-
{
|
| 34 |
-
var b = new CsvDataBinderBenchmarks();
|
| 35 |
-
b.SylvanBench();
|
| 36 |
-
}
|
| 37 |
-
|
| 38 |
-
[Fact]
|
| 39 |
-
public async Task SylvanSchemaBench()
|
| 40 |
-
{
|
| 41 |
-
var b = new CsvReaderBenchmarks();
|
| 42 |
-
await b.SylvanSchema();
|
| 43 |
-
}
|
| 44 |
-
|
| 45 |
-
[Fact]
|
| 46 |
-
public void FinalCRTest()
|
| 47 |
-
{
|
| 48 |
-
var b = CsvDataReader.Create(new StringReader(@"A,B\r\n1,2\r\n1,\r"));
|
| 49 |
-
while (b.Read()) ;
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
[Fact]
|
| 53 |
-
public void MissingFinalFieldTest()
|
| 54 |
-
{
|
| 55 |
-
var b = CsvDataReader.Create(new StringReader(@"A,B\r\n1,2\r\n1,"));
|
| 56 |
-
while (b.Read()) ;
|
| 57 |
-
}
|
| 58 |
-
|
| 59 |
-
[Fact]
|
| 60 |
-
public void MissingFinalField2Test()
|
| 61 |
-
{
|
| 62 |
-
var b = CsvDataReader.Create(new StringReader(@"A,B\r\n1"));
|
| 63 |
-
while (b.Read()) ;
|
| 64 |
-
}
|
| 65 |
-
|
| 66 |
-
[Fact]
|
| 67 |
-
public async Task Simple()
|
| 68 |
-
{
|
| 69 |
-
using var csv = await CsvDataReader.CreateAsync("Data\\Simple.csv");
|
| 70 |
-
Assert.Equal(4, csv.FieldCount);
|
| 71 |
-
Assert.True(csv.HasRows);
|
| 72 |
-
Assert.Equal(0, csv.RowNumber);
|
| 73 |
-
Assert.Equal("Id", csv.GetName(0));
|
| 74 |
-
Assert.Equal("Name", csv.GetName(1));
|
| 75 |
-
Assert.Equal("Value", csv.GetName(2));
|
| 76 |
-
Assert.Equal("Date", csv.GetName(3));
|
| 77 |
-
Assert.True(await csv.ReadAsync());
|
| 78 |
-
Assert.Equal(1, csv.RowNumber);
|
| 79 |
-
Assert.Equal("1", csv[0]);
|
| 80 |
-
Assert.Equal("John", csv[1]);
|
| 81 |
-
Assert.Equal("Low", csv[2]);
|
| 82 |
-
Assert.Equal("2000-11-11", csv[3]);
|
| 83 |
-
Assert.True(await csv.ReadAsync());
|
| 84 |
-
Assert.Equal(2, csv.RowNumber);
|
| 85 |
-
Assert.Equal("2", csv[0]);
|
| 86 |
-
Assert.Equal("Jane", csv[1]);
|
| 87 |
-
Assert.Equal("High", csv[2]);
|
| 88 |
-
Assert.Equal("1989-03-14", csv[3]);
|
| 89 |
-
Assert.False(await csv.ReadAsync());
|
| 90 |
-
}
|
| 91 |
-
|
| 92 |
-
const string BinaryValue1 = "Hello, world!";
|
| 93 |
-
const string BinaryValue2 = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
|
| 94 |
-
|
| 95 |
-
[Fact]
|
| 96 |
-
public async Task Binary()
|
| 97 |
-
{
|
| 98 |
-
using (var reader = File.OpenText("Data\\Binary.csv"))
|
| 99 |
-
{
|
| 100 |
-
var csv = await CsvDataReader.CreateAsync(reader);
|
| 101 |
-
csv.Read();
|
| 102 |
-
var id = csv.GetInt32(0);
|
| 103 |
-
byte[] buffer = new byte[16];
|
| 104 |
-
var len = csv.GetBytes(1, 0, buffer, 0, 2);
|
| 105 |
-
Assert.Equal(2, len);
|
| 106 |
-
len += csv.GetBytes(1, len, buffer, (int)len, 14);
|
| 107 |
-
Assert.Equal(BinaryValue1.Length, len);
|
| 108 |
-
var expected = Encoding.ASCII.GetBytes(BinaryValue1);
|
| 109 |
-
Assert.Equal(expected, buffer.Take((int)len));
|
| 110 |
-
csv.Read();
|
| 111 |
-
|
| 112 |
-
var p = 0;
|
| 113 |
-
len = 0;
|
| 114 |
-
var sw = new StringWriter();
|
| 115 |
-
while ((len = csv.GetBytes(1, p, buffer, 0, buffer.Length)) != 0)
|
| 116 |
-
{
|
| 117 |
-
p += (int)len;
|
| 118 |
-
sw.Write(Encoding.ASCII.GetString(buffer, 0, (int)len));
|
| 119 |
-
}
|
| 120 |
-
var str = sw.ToString();
|
| 121 |
-
Assert.Equal(BinaryValue2, str);
|
| 122 |
-
}
|
| 123 |
-
}
|
| 124 |
-
|
| 125 |
-
[Fact]
|
| 126 |
-
public async Task BinaryValues()
|
| 127 |
-
{
|
| 128 |
-
using (var reader = File.OpenText("Data\\Binary.csv"))
|
| 129 |
-
{
|
| 130 |
-
var schema = new TypedCsvSchema();
|
| 131 |
-
schema.Add(1, typeof(byte[]));
|
| 132 |
-
var opts = new CsvDataReaderOptions() { Schema = schema };
|
| 133 |
-
var csv = await CsvDataReader.CreateAsync(reader, opts);
|
| 134 |
-
csv.Read();
|
| 135 |
-
var vals = new object[2];
|
| 136 |
-
csv.GetValues(vals);
|
| 137 |
-
var expected = Encoding.ASCII.GetBytes(BinaryValue1);
|
| 138 |
-
Assert.Equal(expected, (byte[])vals[1]);
|
| 139 |
-
csv.Read();
|
| 140 |
-
csv.GetValues(vals);
|
| 141 |
-
expected = Encoding.ASCII.GetBytes(BinaryValue2);
|
| 142 |
-
Assert.Equal(expected, (byte[])vals[1]);
|
| 143 |
-
}
|
| 144 |
-
}
|
| 145 |
-
|
| 146 |
-
[Fact]
|
| 147 |
-
public async Task PartialRecord()
|
| 148 |
-
{
|
| 149 |
-
using (var reader = File.OpenText("Data\\PartialRecord.csv"))
|
| 150 |
-
{
|
| 151 |
-
var csv = await CsvDataReader.CreateAsync(reader);
|
| 152 |
-
Assert.Equal(4, csv.FieldCount);
|
| 153 |
-
Assert.True(csv.HasRows);
|
| 154 |
-
Assert.Equal(0, csv.RowNumber);
|
| 155 |
-
Assert.True(await csv.ReadAsync());
|
| 156 |
-
Assert.Equal(1, csv.RowNumber);
|
| 157 |
-
Assert.Equal("1", csv[0]);
|
| 158 |
-
Assert.Equal("John", csv[1]);
|
| 159 |
-
Assert.False(csv.IsDBNull(2));
|
| 160 |
-
Assert.Equal("Low", csv[2]);
|
| 161 |
-
Assert.False(csv.IsDBNull(3));
|
| 162 |
-
Assert.Equal("", csv[3]);
|
| 163 |
-
}
|
| 164 |
-
}
|
| 165 |
-
|
| 166 |
-
[Fact]
|
| 167 |
-
public async Task Quoted()
|
| 168 |
-
{
|
| 169 |
-
using (var reader = File.OpenText("Data\\Quote.csv"))
|
| 170 |
-
{
|
| 171 |
-
var csv = await CsvDataReader.CreateAsync(reader);
|
| 172 |
-
Assert.Equal(5, csv.FieldCount);
|
| 173 |
-
Assert.True(csv.HasRows);
|
| 174 |
-
Assert.Equal(0, csv.RowNumber);
|
| 175 |
-
Assert.Equal("Id", csv.GetName(0));
|
| 176 |
-
Assert.Equal("Name", csv.GetName(1));
|
| 177 |
-
Assert.Equal("Value", csv.GetName(2));
|
| 178 |
-
Assert.Equal("Date", csv.GetName(3));
|
| 179 |
-
Assert.Equal("Original, Origin", csv.GetName(4));
|
| 180 |
-
Assert.True(await csv.ReadAsync());
|
| 181 |
-
Assert.Equal(1, csv.RowNumber);
|
| 182 |
-
Assert.Equal("1", csv[0]);
|
| 183 |
-
Assert.Equal("John", csv[1]);
|
| 184 |
-
Assert.Equal("Very\r\nLow\r\n", csv[2]);
|
| 185 |
-
Assert.Equal("2000-11-11", csv[3]);
|
| 186 |
-
Assert.True(await csv.ReadAsync());
|
| 187 |
-
Assert.Equal(2, csv.RowNumber);
|
| 188 |
-
Assert.Equal("2", csv[0]);
|
| 189 |
-
Assert.Equal("Jane", csv[1]);
|
| 190 |
-
Assert.Equal("\"High\"", csv[2]);
|
| 191 |
-
Assert.Equal("1989-03-14", csv[3]);
|
| 192 |
-
Assert.True(await csv.ReadAsync());
|
| 193 |
-
Assert.Equal(3, csv.RowNumber);
|
| 194 |
-
Assert.Equal("3", csv[0]);
|
| 195 |
-
Assert.Equal("Comma", csv[1]);
|
| 196 |
-
Assert.Equal("Quite, Common", csv[2]);
|
| 197 |
-
Assert.Equal("2020-05-29", csv[3]);
|
| 198 |
-
Assert.Equal("", csv[4]);
|
| 199 |
-
Assert.False(await csv.ReadAsync());
|
| 200 |
-
}
|
| 201 |
-
}
|
| 202 |
-
|
| 203 |
-
[Fact]
|
| 204 |
-
public void Quoted2()
|
| 205 |
-
{
|
| 206 |
-
var reader = new StringReader("a,b,c\n1,\"\"\"2\"\", (two)\",3");
|
| 207 |
-
var csv = CsvDataReader.Create(reader);
|
| 208 |
-
Assert.Equal(3, csv.FieldCount);
|
| 209 |
-
csv.Read();
|
| 210 |
-
Assert.Equal("1", csv.GetString(0));
|
| 211 |
-
Assert.Equal("\"2\", (two)", csv.GetString(1));
|
| 212 |
-
Assert.Equal("3", csv.GetString(2));
|
| 213 |
-
}
|
| 214 |
-
|
| 215 |
-
[Fact]
|
| 216 |
-
public void MissingHeaders()
|
| 217 |
-
{
|
| 218 |
-
Assert.Throws<CsvMissingHeadersException>(() => CsvDataReader.Create(new StringReader("")));
|
| 219 |
-
}
|
| 220 |
-
|
| 221 |
-
[Fact]
|
| 222 |
-
public async Task NoHeaders()
|
| 223 |
-
{
|
| 224 |
-
using (var reader = File.OpenText("Data\\DataOnly.csv"))
|
| 225 |
-
{
|
| 226 |
-
var csv = await CsvDataReader.CreateAsync(reader, new CsvDataReaderOptions { HasHeaders = false });
|
| 227 |
-
Assert.Equal(4, csv.FieldCount);
|
| 228 |
-
Assert.True(csv.HasRows);
|
| 229 |
-
Assert.Equal(0, csv.RowNumber);
|
| 230 |
-
Assert.Equal("", csv.GetName(0));
|
| 231 |
-
Assert.Throws<IndexOutOfRangeException>(() => csv.GetOrdinal("Id"));
|
| 232 |
-
Assert.True(await csv.ReadAsync());
|
| 233 |
-
Assert.Equal(1, csv.RowNumber);
|
| 234 |
-
Assert.Equal("1", csv[0]);
|
| 235 |
-
Assert.Equal("John", csv[1]);
|
| 236 |
-
Assert.Equal("Low", csv[2]);
|
| 237 |
-
Assert.Equal("2000-11-11", csv[3]);
|
| 238 |
-
Assert.True(await csv.ReadAsync());
|
| 239 |
-
Assert.Equal(2, csv.RowNumber);
|
| 240 |
-
Assert.Equal("2", csv[0]);
|
| 241 |
-
Assert.Equal("Jane", csv[1]);
|
| 242 |
-
Assert.Equal("High", csv[2]);
|
| 243 |
-
Assert.Equal("1989-03-14", csv[3]);
|
| 244 |
-
Assert.False(await csv.ReadAsync());
|
| 245 |
-
}
|
| 246 |
-
}
|
| 247 |
-
|
| 248 |
-
[Fact]
|
| 249 |
-
public async Task NoHeadersWithSchema()
|
| 250 |
-
{
|
| 251 |
-
var schema = new ExcelHeaders();
|
| 252 |
-
var opts =
|
| 253 |
-
new CsvDataReaderOptions
|
| 254 |
-
{
|
| 255 |
-
HasHeaders = false,
|
| 256 |
-
Schema = schema
|
| 257 |
-
};
|
| 258 |
-
|
| 259 |
-
using (var reader = File.OpenText("Data\\DataOnly.csv"))
|
| 260 |
-
{
|
| 261 |
-
var csv = await CsvDataReader.CreateAsync(reader, opts);
|
| 262 |
-
Assert.Equal(4, csv.FieldCount);
|
| 263 |
-
Assert.True(csv.HasRows);
|
| 264 |
-
Assert.Equal(0, csv.RowNumber);
|
| 265 |
-
Assert.Equal("C", csv.GetName(2));
|
| 266 |
-
Assert.Equal(3, csv.GetOrdinal("D"));
|
| 267 |
-
Assert.Equal("A", csv.GetName(0));
|
| 268 |
-
Assert.Throws<IndexOutOfRangeException>(() => csv.GetOrdinal("Id"));
|
| 269 |
-
Assert.True(await csv.ReadAsync());
|
| 270 |
-
Assert.Equal(1, csv.RowNumber);
|
| 271 |
-
Assert.Equal("1", csv[0]);
|
| 272 |
-
Assert.Equal("John", csv[1]);
|
| 273 |
-
Assert.Equal("Low", csv[2]);
|
| 274 |
-
Assert.Equal("2000-11-11", csv[3]);
|
| 275 |
-
Assert.True(await csv.ReadAsync());
|
| 276 |
-
Assert.Equal(2, csv.RowNumber);
|
| 277 |
-
Assert.Equal("2", csv[0]);
|
| 278 |
-
Assert.Equal("Jane", csv[1]);
|
| 279 |
-
Assert.Equal("High", csv[2]);
|
| 280 |
-
Assert.Equal("1989-03-14", csv[3]);
|
| 281 |
-
Assert.False(await csv.ReadAsync());
|
| 282 |
-
}
|
| 283 |
-
}
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
[Theory]
|
| 287 |
-
[InlineData("Id,Name,Value,Date")]
|
| 288 |
-
[InlineData("Id,Name,Value,Date\n")]
|
| 289 |
-
[InlineData("Id,Name,Value,Date\r\n")]
|
| 290 |
-
public async Task HeadersOnly(string data)
|
| 291 |
-
{
|
| 292 |
-
using (var reader = new StringReader(data))
|
| 293 |
-
{
|
| 294 |
-
var csv = await CsvDataReader.CreateAsync(reader);
|
| 295 |
-
Assert.Equal(4, csv.FieldCount);
|
| 296 |
-
Assert.False(csv.HasRows);
|
| 297 |
-
Assert.Equal(0, csv.RowNumber);
|
| 298 |
-
Assert.Equal("Id", csv.GetName(0));
|
| 299 |
-
Assert.Equal("Name", csv.GetName(1));
|
| 300 |
-
Assert.Equal("Value", csv.GetName(2));
|
| 301 |
-
Assert.Equal("Date", csv.GetName(3));
|
| 302 |
-
Assert.False(await csv.ReadAsync());
|
| 303 |
-
}
|
| 304 |
-
}
|
| 305 |
-
|
| 306 |
-
[Fact]
|
| 307 |
-
public async Task TestBig()
|
| 308 |
-
{
|
| 309 |
-
var tr = TestData.GetTextReader();
|
| 310 |
-
string str = null;
|
| 311 |
-
|
| 312 |
-
var csv = await CsvDataReader.CreateAsync(tr);
|
| 313 |
-
while (await csv.ReadAsync())
|
| 314 |
-
{
|
| 315 |
-
var s = csv.GetString(0);
|
| 316 |
-
var v = csv.GetInt32(0);
|
| 317 |
-
var n = csv.GetString(10);
|
| 318 |
-
|
| 319 |
-
for (int i = 0; i < csv.FieldCount; i++)
|
| 320 |
-
{
|
| 321 |
-
str = csv.GetString(i);
|
| 322 |
-
}
|
| 323 |
-
var v1 = csv.GetInt32(20);
|
| 324 |
-
}
|
| 325 |
-
// there was previously a bug, where the last value was read as "103\n".
|
| 326 |
-
Assert.Equal("103", str);
|
| 327 |
-
}
|
| 328 |
-
|
| 329 |
-
[Fact]
|
| 330 |
-
public void Sync()
|
| 331 |
-
{
|
| 332 |
-
using (var reader = File.OpenText("Data\\Simple.csv"))
|
| 333 |
-
{
|
| 334 |
-
var csv = CsvDataReader.Create(reader);
|
| 335 |
-
Assert.Equal(4, csv.FieldCount);
|
| 336 |
-
Assert.True(csv.HasRows);
|
| 337 |
-
Assert.Equal(0, csv.RowNumber);
|
| 338 |
-
Assert.Equal("Id", csv.GetName(0));
|
| 339 |
-
Assert.Equal("Name", csv.GetName(1));
|
| 340 |
-
Assert.Equal("Value", csv.GetName(2));
|
| 341 |
-
Assert.Equal("Date", csv.GetName(3));
|
| 342 |
-
Assert.True(csv.Read());
|
| 343 |
-
Assert.Equal(1, csv.RowNumber);
|
| 344 |
-
Assert.Equal("1", csv[0]);
|
| 345 |
-
Assert.Equal("John", csv[1]);
|
| 346 |
-
Assert.Equal("Low", csv[2]);
|
| 347 |
-
Assert.Equal("2000-11-11", csv[3]);
|
| 348 |
-
Assert.True(csv.Read());
|
| 349 |
-
Assert.Equal(2, csv.RowNumber);
|
| 350 |
-
Assert.Equal("2", csv[0]);
|
| 351 |
-
Assert.Equal("Jane", csv[1]);
|
| 352 |
-
Assert.Equal("High", csv[2]);
|
| 353 |
-
Assert.Equal("1989-03-14", csv[3]);
|
| 354 |
-
Assert.False(csv.Read());
|
| 355 |
-
}
|
| 356 |
-
}
|
| 357 |
-
|
| 358 |
-
[Fact]
|
| 359 |
-
public void Broken()
|
| 360 |
-
{
|
| 361 |
-
using (var reader = File.OpenText("Data\\Broken.csv"))
|
| 362 |
-
{
|
| 363 |
-
var csv = CsvDataReader.Create(reader);
|
| 364 |
-
Assert.Equal(2, csv.FieldCount);
|
| 365 |
-
Assert.True(csv.HasRows);
|
| 366 |
-
Assert.Equal(0, csv.RowNumber);
|
| 367 |
-
Assert.Equal("A", csv.GetName(0));
|
| 368 |
-
Assert.Equal("B", csv.GetName(1));
|
| 369 |
-
Assert.True(csv.Read());
|
| 370 |
-
Assert.Equal(1, csv.RowNumber);
|
| 371 |
-
Assert.Equal("ab", csv[0]);
|
| 372 |
-
Assert.Equal("c", csv[1]);
|
| 373 |
-
Assert.True(csv.Read());
|
| 374 |
-
Assert.Equal(2, csv.RowNumber);
|
| 375 |
-
Assert.Equal("d\"e\"f", csv[0]);
|
| 376 |
-
Assert.Equal("gh\"i", csv[1]);
|
| 377 |
-
Assert.False(csv.Read());
|
| 378 |
-
}
|
| 379 |
-
}
|
| 380 |
-
|
| 381 |
-
[Fact]
|
| 382 |
-
public void CustomSchema()
|
| 383 |
-
{
|
| 384 |
-
using var sr = TestData.GetTextReader();
|
| 385 |
-
var schema = new TypedCsvSchema();
|
| 386 |
-
schema.Add("UID", typeof(int));
|
| 387 |
-
var csv = CsvDataReader.Create(sr, new CsvDataReaderOptions { Schema = schema });
|
| 388 |
-
}
|
| 389 |
-
|
| 390 |
-
[Fact]
|
| 391 |
-
public void GetColumnSchema()
|
| 392 |
-
{
|
| 393 |
-
using (var reader = File.OpenText("Data\\Simple.csv"))
|
| 394 |
-
{
|
| 395 |
-
var csv = CsvDataReader.Create(reader);
|
| 396 |
-
var cols = csv.GetColumnSchema();
|
| 397 |
-
|
| 398 |
-
var names = new[] { "Id", "Name", "Value", "Date" };
|
| 399 |
-
for (int i = 0; i < cols.Count; i++)
|
| 400 |
-
{
|
| 401 |
-
Assert.Equal(names[i], cols[i].ColumnName);
|
| 402 |
-
Assert.Equal(typeof(string), cols[i].DataType);
|
| 403 |
-
}
|
| 404 |
-
}
|
| 405 |
-
}
|
| 406 |
-
|
| 407 |
-
class ExcelHeaders : ICsvSchemaProvider
|
| 408 |
-
{
|
| 409 |
-
public DbColumn GetColumn(string name, int ordinal)
|
| 410 |
-
{
|
| 411 |
-
return new ExcelColumn("" + (char)('A' + ordinal), ordinal);
|
| 412 |
-
}
|
| 413 |
-
|
| 414 |
-
class ExcelColumn : DbColumn
|
| 415 |
-
{
|
| 416 |
-
public ExcelColumn(string name, int ordinal)
|
| 417 |
-
{
|
| 418 |
-
this.ColumnName = name;
|
| 419 |
-
this.ColumnOrdinal = ordinal;
|
| 420 |
-
}
|
| 421 |
-
}
|
| 422 |
-
}
|
| 423 |
-
|
| 424 |
-
[Fact]
|
| 425 |
-
public void DupeHeader()
|
| 426 |
-
{
|
| 427 |
-
var data = "a,b,b";
|
| 428 |
-
|
| 429 |
-
var csv = CsvDataReader.Create(new StringReader(data));
|
| 430 |
-
Assert.Equal(0, csv.GetOrdinal("a"));
|
| 431 |
-
Assert.Throws<AmbiguousColumnException>(() => csv.GetOrdinal("b"));
|
| 432 |
-
var schema = csv.GetColumnSchema();
|
| 433 |
-
Assert.Equal("a", schema[0].ColumnName);
|
| 434 |
-
Assert.Equal("b", schema[1].ColumnName);
|
| 435 |
-
Assert.Equal("b", schema[2].ColumnName);
|
| 436 |
-
}
|
| 437 |
-
|
| 438 |
-
[Fact]
|
| 439 |
-
public void DupeHeaderFix()
|
| 440 |
-
{
|
| 441 |
-
var data = "a,b,c,d,e,e";
|
| 442 |
-
|
| 443 |
-
var fixSchema = new ExcelHeaders();
|
| 444 |
-
var opts = new CsvDataReaderOptions { Schema = fixSchema };
|
| 445 |
-
|
| 446 |
-
var csv = CsvDataReader.Create(new StringReader(data), opts);
|
| 447 |
-
Assert.Equal(6, csv.FieldCount);
|
| 448 |
-
|
| 449 |
-
}
|
| 450 |
-
|
| 451 |
-
class FixHeaders : ICsvSchemaProvider
|
| 452 |
-
{
|
| 453 |
-
|
| 454 |
-
HashSet<string> h;
|
| 455 |
-
|
| 456 |
-
public FixHeaders()
|
| 457 |
-
{
|
| 458 |
-
this.h = new HashSet<string>();
|
| 459 |
-
}
|
| 460 |
-
|
| 461 |
-
class Column : DbColumn
|
| 462 |
-
{
|
| 463 |
-
public Column(string orignalName, string name)
|
| 464 |
-
{
|
| 465 |
-
this.BaseColumnName = orignalName;
|
| 466 |
-
this.ColumnName = name;
|
| 467 |
-
}
|
| 468 |
-
}
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
public DbColumn GetColumn(string name, int ordinal)
|
| 472 |
-
{
|
| 473 |
-
if (h.Add(name))
|
| 474 |
-
{
|
| 475 |
-
return new Column(name, name);
|
| 476 |
-
}
|
| 477 |
-
for (int i = 2; i < 100; i++)
|
| 478 |
-
{
|
| 479 |
-
var dedupe = name + i;
|
| 480 |
-
if (h.Add(dedupe))
|
| 481 |
-
{
|
| 482 |
-
return new Column(name, dedupe);
|
| 483 |
-
}
|
| 484 |
-
}
|
| 485 |
-
|
| 486 |
-
//exceptions are better than infinite loops.
|
| 487 |
-
throw new NotSupportedException();
|
| 488 |
-
}
|
| 489 |
-
}
|
| 490 |
-
|
| 491 |
-
[Fact]
|
| 492 |
-
public void DupeHeaderFix2()
|
| 493 |
-
{
|
| 494 |
-
var data = "a,a,b,b,c,c";
|
| 495 |
-
|
| 496 |
-
var fixSchema = new FixHeaders();
|
| 497 |
-
var opts = new CsvDataReaderOptions { Schema = fixSchema };
|
| 498 |
-
|
| 499 |
-
var csv = CsvDataReader.Create(new StringReader(data), opts);
|
| 500 |
-
Assert.Equal(6, csv.FieldCount);
|
| 501 |
-
|
| 502 |
-
}
|
| 503 |
-
|
| 504 |
-
[Fact]
|
| 505 |
-
public void GetSchemaTable()
|
| 506 |
-
{
|
| 507 |
-
using (var reader = File.OpenText("Data\\Simple.csv"))
|
| 508 |
-
{
|
| 509 |
-
var csv = CsvDataReader.Create(reader);
|
| 510 |
-
var schema = csv.GetSchemaTable();
|
| 511 |
-
|
| 512 |
-
var names = new[] { "Id", "Name", "Value", "Date" };
|
| 513 |
-
for (int i = 0; i < schema.Rows.Count; i++)
|
| 514 |
-
{
|
| 515 |
-
var row = schema.Rows[i];
|
| 516 |
-
Assert.Equal(names[i], (string)row["ColumnName"]);
|
| 517 |
-
Assert.Equal(typeof(string), (Type)row["DataType"]);
|
| 518 |
-
}
|
| 519 |
-
}
|
| 520 |
-
}
|
| 521 |
-
|
| 522 |
-
[Fact]
|
| 523 |
-
public void Enumerator()
|
| 524 |
-
{
|
| 525 |
-
using (var reader = File.OpenText("Data\\Simple.csv"))
|
| 526 |
-
{
|
| 527 |
-
var csv = CsvDataReader.Create(reader);
|
| 528 |
-
int c = 0;
|
| 529 |
-
foreach (IDataRecord row in csv)
|
| 530 |
-
{
|
| 531 |
-
c++;
|
| 532 |
-
Assert.Same(row, csv);
|
| 533 |
-
}
|
| 534 |
-
Assert.Equal(2, c);
|
| 535 |
-
}
|
| 536 |
-
}
|
| 537 |
-
|
| 538 |
-
[Fact]
|
| 539 |
-
public void Create()
|
| 540 |
-
{
|
| 541 |
-
Assert.ThrowsAsync<ArgumentNullException>(() => CsvDataReader.CreateAsync((TextReader)null));
|
| 542 |
-
}
|
| 543 |
-
|
| 544 |
-
[Fact]
|
| 545 |
-
public void BufferTooSmall()
|
| 546 |
-
{
|
| 547 |
-
var opts = new CsvDataReaderOptions() { BufferSize = 128 };
|
| 548 |
-
using var tr = File.OpenText("Data\\Binary.csv");
|
| 549 |
-
var csv = CsvDataReader.Create(tr, opts);
|
| 550 |
-
csv.Read();
|
| 551 |
-
Assert.Throws<CsvRecordTooLargeException>(() => csv.Read());
|
| 552 |
-
}
|
| 553 |
-
|
| 554 |
-
[Fact]
|
| 555 |
-
public void NextResult()
|
| 556 |
-
{
|
| 557 |
-
using var tr = File.OpenText("Data\\Binary.csv");
|
| 558 |
-
var csv = CsvDataReader.Create(tr);
|
| 559 |
-
Assert.False(csv.NextResult());
|
| 560 |
-
Assert.False(csv.Read());
|
| 561 |
-
}
|
| 562 |
-
|
| 563 |
-
[Fact]
|
| 564 |
-
public async Task NextResultAsync()
|
| 565 |
-
{
|
| 566 |
-
using var tr = File.OpenText("Data\\Binary.csv");
|
| 567 |
-
var csv = CsvDataReader.Create(tr);
|
| 568 |
-
Assert.False(await csv.NextResultAsync());
|
| 569 |
-
Assert.False(await csv.ReadAsync());
|
| 570 |
-
}
|
| 571 |
-
|
| 572 |
-
CsvDataReader GetTypedReader()
|
| 573 |
-
{
|
| 574 |
-
var tr = File.OpenText("Data\\Types.csv");
|
| 575 |
-
var schema = new TypedCsvSchema();
|
| 576 |
-
schema.Add("Byte", typeof(byte));
|
| 577 |
-
schema.Add("Int16", typeof(short));
|
| 578 |
-
schema.Add("Int32", typeof(int));
|
| 579 |
-
schema.Add("Int64", typeof(long));
|
| 580 |
-
schema.Add("Char", typeof(char));
|
| 581 |
-
schema.Add("String", typeof(string));
|
| 582 |
-
schema.Add("Bool", typeof(bool));
|
| 583 |
-
schema.Add("Float", typeof(float));
|
| 584 |
-
schema.Add("Double", typeof(double));
|
| 585 |
-
schema.Add("DateTime", typeof(DateTime));
|
| 586 |
-
schema.Add("Decimal", typeof(decimal));
|
| 587 |
-
schema.Add("Guid", typeof(Guid));
|
| 588 |
-
|
| 589 |
-
var opts = new CsvDataReaderOptions() { Schema = schema };
|
| 590 |
-
|
| 591 |
-
return CsvDataReader.Create(tr, opts);
|
| 592 |
-
}
|
| 593 |
-
|
| 594 |
-
[Fact]
|
| 595 |
-
public void Types()
|
| 596 |
-
{
|
| 597 |
-
var csv = GetTypedReader();
|
| 598 |
-
csv.Read();
|
| 599 |
-
var rowData = new object[csv.FieldCount];
|
| 600 |
-
var count = csv.GetValues(rowData);
|
| 601 |
-
var types = new HashSet<string>();
|
| 602 |
-
for (var i = 0; i < csv.FieldCount; i++)
|
| 603 |
-
{
|
| 604 |
-
Assert.True(types.Add(csv.GetDataTypeName(i)));
|
| 605 |
-
}
|
| 606 |
-
Assert.Equal(rowData.Length, count);
|
| 607 |
-
foreach (var obj in rowData)
|
| 608 |
-
{
|
| 609 |
-
Assert.NotNull(obj);
|
| 610 |
-
}
|
| 611 |
-
}
|
| 612 |
-
|
| 613 |
-
[Fact]
|
| 614 |
-
public void TextReader()
|
| 615 |
-
{
|
| 616 |
-
using var tr = File.OpenText("Data\\Binary.csv");
|
| 617 |
-
var csv = CsvDataReader.Create(tr);
|
| 618 |
-
var buf = new char[32];
|
| 619 |
-
while (csv.Read())
|
| 620 |
-
{
|
| 621 |
-
var idx = 0;
|
| 622 |
-
int len;
|
| 623 |
-
while ((len = (int)csv.GetChars(1, idx, buf, 0, buf.Length)) != 0)
|
| 624 |
-
{
|
| 625 |
-
idx += len;
|
| 626 |
-
}
|
| 627 |
-
|
| 628 |
-
Assert.True(idx > 0);
|
| 629 |
-
}
|
| 630 |
-
}
|
| 631 |
-
|
| 632 |
-
[Fact]
|
| 633 |
-
public void LineEndings()
|
| 634 |
-
{
|
| 635 |
-
using var tr = new StringReader("Id\r1\r\n2\n3\n\r");
|
| 636 |
-
var csv = CsvDataReader.Create(tr);
|
| 637 |
-
Assert.Equal("Id", csv.GetName(0));
|
| 638 |
-
Assert.True(csv.Read());
|
| 639 |
-
Assert.Equal("1", csv.GetString(0));
|
| 640 |
-
Assert.True(csv.Read());
|
| 641 |
-
Assert.Equal("2", csv.GetString(0));
|
| 642 |
-
Assert.True(csv.Read());
|
| 643 |
-
Assert.Equal("3", csv.GetString(0));
|
| 644 |
-
Assert.True(csv.Read());
|
| 645 |
-
Assert.Equal("", csv.GetString(0));
|
| 646 |
-
Assert.False(csv.Read());
|
| 647 |
-
}
|
| 648 |
-
|
| 649 |
-
[Fact]
|
| 650 |
-
public void MiscCoverage()
|
| 651 |
-
{
|
| 652 |
-
using var tr = new StringReader("Id,Name,Value");
|
| 653 |
-
var csv = CsvDataReader.Create(tr);
|
| 654 |
-
Assert.False(csv.HasRows);
|
| 655 |
-
Assert.Equal(0, csv.Depth);
|
| 656 |
-
Assert.False(csv.IsClosed);
|
| 657 |
-
Assert.Equal(-1, csv.RecordsAffected);
|
| 658 |
-
}
|
| 659 |
-
|
| 660 |
-
[Fact]
|
| 661 |
-
public void Boolean1()
|
| 662 |
-
{
|
| 663 |
-
using var tr = new StringReader("Bool\nT\nF\nX\n");
|
| 664 |
-
var opts = new CsvDataReaderOptions()
|
| 665 |
-
{
|
| 666 |
-
TrueString = "t",
|
| 667 |
-
FalseString = "f",
|
| 668 |
-
};
|
| 669 |
-
var csv = CsvDataReader.Create(tr, opts);
|
| 670 |
-
Assert.True(csv.Read());
|
| 671 |
-
Assert.True(csv.GetBoolean(0));
|
| 672 |
-
Assert.True(csv.Read());
|
| 673 |
-
Assert.False(csv.GetBoolean(0));
|
| 674 |
-
Assert.True(csv.Read());
|
| 675 |
-
Assert.Throws<FormatException>(() => csv.GetBoolean(0));
|
| 676 |
-
}
|
| 677 |
-
|
| 678 |
-
[Fact]
|
| 679 |
-
public void Boolean2()
|
| 680 |
-
{
|
| 681 |
-
using var tr = new StringReader("Bool\nT\nF\nX\n");
|
| 682 |
-
var opts = new CsvDataReaderOptions()
|
| 683 |
-
{
|
| 684 |
-
TrueString = "t",
|
| 685 |
-
FalseString = null,
|
| 686 |
-
};
|
| 687 |
-
var csv = CsvDataReader.Create(tr, opts);
|
| 688 |
-
Assert.True(csv.Read());
|
| 689 |
-
Assert.True(csv.GetBoolean(0));
|
| 690 |
-
Assert.True(csv.Read());
|
| 691 |
-
Assert.False(csv.GetBoolean(0));
|
| 692 |
-
Assert.True(csv.Read());
|
| 693 |
-
Assert.False(csv.GetBoolean(0));
|
| 694 |
-
}
|
| 695 |
-
|
| 696 |
-
[Fact]
|
| 697 |
-
public void Boolean3()
|
| 698 |
-
{
|
| 699 |
-
using var tr = new StringReader("Bool\nT\nF\nX\n");
|
| 700 |
-
var opts = new CsvDataReaderOptions()
|
| 701 |
-
{
|
| 702 |
-
TrueString = null,
|
| 703 |
-
FalseString = "f",
|
| 704 |
-
};
|
| 705 |
-
var csv = CsvDataReader.Create(tr, opts);
|
| 706 |
-
Assert.True(csv.Read());
|
| 707 |
-
Assert.True(csv.GetBoolean(0));
|
| 708 |
-
Assert.True(csv.Read());
|
| 709 |
-
Assert.False(csv.GetBoolean(0));
|
| 710 |
-
Assert.True(csv.Read());
|
| 711 |
-
Assert.True(csv.GetBoolean(0));
|
| 712 |
-
}
|
| 713 |
-
|
| 714 |
-
[Fact]
|
| 715 |
-
public void Date1()
|
| 716 |
-
{
|
| 717 |
-
using var tr = new StringReader("Date\n20200803\n20200804\n20200805\n");
|
| 718 |
-
var opts = new CsvDataReaderOptions()
|
| 719 |
-
{
|
| 720 |
-
DateFormat = "yyyyMMdd"
|
| 721 |
-
};
|
| 722 |
-
var csv = CsvDataReader.Create(tr, opts);
|
| 723 |
-
Assert.True(csv.Read());
|
| 724 |
-
Assert.Equal(new DateTime(2020, 8, 3), csv.GetDateTime(0));
|
| 725 |
-
Assert.True(csv.Read());
|
| 726 |
-
Assert.Equal(new DateTime(2020, 8, 4), csv.GetDateTime(0));
|
| 727 |
-
Assert.True(csv.Read());
|
| 728 |
-
Assert.Equal(new DateTime(2020, 8, 5), csv.GetDateTime(0));
|
| 729 |
-
}
|
| 730 |
-
|
| 731 |
-
|
| 732 |
-
//[Fact]
|
| 733 |
-
//public void DeDupeString()
|
| 734 |
-
//{
|
| 735 |
-
// using var tr = new StringReader("Name\nABC\nABC\nBCD\nBCD\n");
|
| 736 |
-
// var opts = new CsvDataReaderOptions()
|
| 737 |
-
// {
|
| 738 |
-
// PoolStrings = true
|
| 739 |
-
// };
|
| 740 |
-
// var csv = CsvDataReader.Create(tr, opts);
|
| 741 |
-
// Assert.True(csv.Read());
|
| 742 |
-
// var str1 = csv.GetString(0);
|
| 743 |
-
// Assert.Equal("ABC", str1);
|
| 744 |
-
// Assert.True(csv.Read());
|
| 745 |
-
// var str2 = csv.GetString(0);
|
| 746 |
-
// Assert.Equal("ABC", str2);
|
| 747 |
-
// Assert.Same(str1, str2);
|
| 748 |
-
|
| 749 |
-
// Assert.True(csv.Read());
|
| 750 |
-
// str1 = csv.GetString(0);
|
| 751 |
-
// Assert.Equal("BCD", str1);
|
| 752 |
-
// Assert.True(csv.Read());
|
| 753 |
-
// str2 = csv.GetString(0);
|
| 754 |
-
// Assert.Equal("BCD", str2);
|
| 755 |
-
// Assert.Same(str2, str2);
|
| 756 |
-
//}
|
| 757 |
-
|
| 758 |
-
|
| 759 |
-
|
| 760 |
-
[Fact]
|
| 761 |
-
public void AutoDetect1()
|
| 762 |
-
{
|
| 763 |
-
using var tr = new StringReader("A;B;C;D;E\n1;2;3;4;5\n");
|
| 764 |
-
var csv = CsvDataReader.Create(tr);
|
| 765 |
-
Assert.Equal(5, csv.FieldCount);
|
| 766 |
-
Assert.Equal("A", csv.GetName(0));
|
| 767 |
-
Assert.Equal("D", csv.GetName(3));
|
| 768 |
-
}
|
| 769 |
-
|
| 770 |
-
[Fact]
|
| 771 |
-
public void AutoDetect2()
|
| 772 |
-
{
|
| 773 |
-
using var tr = new StringReader("A|B,(b)|C|D|E\n1|2|3|4|5\n");
|
| 774 |
-
var csv = CsvDataReader.Create(tr);
|
| 775 |
-
Assert.Equal(5, csv.FieldCount);
|
| 776 |
-
Assert.Equal("A", csv.GetName(0));
|
| 777 |
-
Assert.Equal("D", csv.GetName(3));
|
| 778 |
-
}
|
| 779 |
-
|
| 780 |
-
[Fact]
|
| 781 |
-
public void MissingFieldTest()
|
| 782 |
-
{
|
| 783 |
-
using var tr = new StringReader("a,b,c\n1,2,3\n4,5\n6,7,8\n");
|
| 784 |
-
var csv = CsvDataReader.Create(tr);
|
| 785 |
-
Assert.True(csv.Read());
|
| 786 |
-
Assert.True(csv.Read());
|
| 787 |
-
Assert.Equal("4", csv.GetString(0));
|
| 788 |
-
Assert.Equal("5", csv.GetString(1));
|
| 789 |
-
Assert.Equal("", csv.GetString(2));
|
| 790 |
-
Assert.False(csv.IsDBNull(0));
|
| 791 |
-
Assert.False(csv.IsDBNull(1));
|
| 792 |
-
Assert.False(csv.IsDBNull(2));
|
| 793 |
-
Assert.Throws<ArgumentOutOfRangeException>(() => csv.GetString(-1));
|
| 794 |
-
Assert.Throws<ArgumentOutOfRangeException>(() => csv.GetString(3));
|
| 795 |
-
}
|
| 796 |
-
|
| 797 |
-
[Fact]
|
| 798 |
-
public void CustomFormatTest()
|
| 799 |
-
{
|
| 800 |
-
var schema = Schema.Parse("Name,Date:DateTime{yyyyMMdd}");
|
| 801 |
-
var csvSchema = new CsvSchema(schema.GetColumnSchema());
|
| 802 |
-
using var tr = new StringReader("Test,20200812");
|
| 803 |
-
var csv = CsvDataReader.Create(tr, new CsvDataReaderOptions { Schema = csvSchema, HasHeaders = false });
|
| 804 |
-
Assert.True(csv.Read());
|
| 805 |
-
Assert.Equal("Test", csv.GetString(0));
|
| 806 |
-
Assert.Equal(new DateTime(2020, 8, 12), csv.GetDateTime(1));
|
| 807 |
-
}
|
| 808 |
-
|
| 809 |
-
|
| 810 |
-
[Fact]
|
| 811 |
-
public void EmptyStringTest()
|
| 812 |
-
{
|
| 813 |
-
using var tr = new StringReader("Name,Value\r\nTest,");
|
| 814 |
-
var csv = CsvDataReader.Create(tr);
|
| 815 |
-
Assert.True(csv.Read());
|
| 816 |
-
Assert.Equal("Test", csv.GetString(0));
|
| 817 |
-
Assert.False(csv.IsDBNull(1));
|
| 818 |
-
Assert.Equal("", csv.GetValue(1));
|
| 819 |
-
}
|
| 820 |
-
|
| 821 |
-
[Fact]
|
| 822 |
-
public void DbNullTest()
|
| 823 |
-
{
|
| 824 |
-
using var tr = new StringReader("Name,Value\r\nTest,");
|
| 825 |
-
var csv = CsvDataReader.Create(tr, new CsvDataReaderOptions { Schema = CsvSchema.Nullable });
|
| 826 |
-
Assert.True(csv.Read());
|
| 827 |
-
Assert.Equal("Test", csv.GetString(0));
|
| 828 |
-
Assert.True(csv.IsDBNull(1));
|
| 829 |
-
Assert.Equal(DBNull.Value, csv.GetValue(1));
|
| 830 |
-
}
|
| 831 |
-
|
| 832 |
-
[Fact]
|
| 833 |
-
public void EmptyString2Test()
|
| 834 |
-
{
|
| 835 |
-
using var tr = new StringReader("Name,Value\r\nTest");
|
| 836 |
-
var csv = CsvDataReader.Create(tr);
|
| 837 |
-
Assert.True(csv.Read());
|
| 838 |
-
Assert.Equal("Test", csv.GetString(0));
|
| 839 |
-
Assert.False(csv.IsDBNull(1));
|
| 840 |
-
Assert.Equal("", csv.GetValue(1));
|
| 841 |
-
}
|
| 842 |
-
|
| 843 |
-
[Fact]
|
| 844 |
-
public void DbNull2Test()
|
| 845 |
-
{
|
| 846 |
-
using var tr = new StringReader("Name,Value\r\nTest");
|
| 847 |
-
var csv = CsvDataReader.Create(tr, new CsvDataReaderOptions { Schema = CsvSchema.Nullable });
|
| 848 |
-
Assert.True(csv.Read());
|
| 849 |
-
Assert.Equal("Test", csv.GetString(0));
|
| 850 |
-
Assert.True(csv.IsDBNull(1));
|
| 851 |
-
Assert.Equal(DBNull.Value, csv.GetValue(1));
|
| 852 |
-
}
|
| 853 |
-
|
| 854 |
-
|
| 855 |
-
[Fact]
|
| 856 |
-
public void RowFieldCountTest()
|
| 857 |
-
{
|
| 858 |
-
using var tr = new StringReader("Name,Value\r\nTest");
|
| 859 |
-
var csv = CsvDataReader.Create(tr, new CsvDataReaderOptions { Schema = CsvSchema.Nullable });
|
| 860 |
-
Assert.True(csv.Read());
|
| 861 |
-
Assert.Equal("Test", csv.GetString(0));
|
| 862 |
-
Assert.Equal(2, csv.FieldCount);
|
| 863 |
-
Assert.Equal(1, csv.RowFieldCount);
|
| 864 |
-
}
|
| 865 |
-
|
| 866 |
-
[Fact]
|
| 867 |
-
public void RowFieldCount2Test()
|
| 868 |
-
{
|
| 869 |
-
using var tr = new StringReader("Name,Value\r\n\r\n");
|
| 870 |
-
var csv = CsvDataReader.Create(tr, new CsvDataReaderOptions { Schema = CsvSchema.Nullable });
|
| 871 |
-
Assert.True(csv.Read());
|
| 872 |
-
Assert.Equal(2, csv.FieldCount);
|
| 873 |
-
Assert.Equal(1, csv.RowFieldCount);
|
| 874 |
-
}
|
| 875 |
-
|
| 876 |
-
[Fact]
|
| 877 |
-
public void RowFieldCount3Test()
|
| 878 |
-
{
|
| 879 |
-
using var tr = new StringReader("Name,Value\r\n,,\r\n");
|
| 880 |
-
var csv = CsvDataReader.Create(tr, new CsvDataReaderOptions { Schema = CsvSchema.Nullable });
|
| 881 |
-
Assert.True(csv.Read());
|
| 882 |
-
Assert.Equal(2, csv.FieldCount);
|
| 883 |
-
Assert.Equal(3, csv.RowFieldCount);
|
| 884 |
-
}
|
| 885 |
-
|
| 886 |
-
[Fact]
|
| 887 |
-
public void BadQuote()
|
| 888 |
-
{
|
| 889 |
-
using var tr = new StringReader("Name,Value\r\nA\"\"B,\"And\"more,\r\n");
|
| 890 |
-
var csv = CsvDataReader.Create(tr, new CsvDataReaderOptions { Schema = CsvSchema.Nullable });
|
| 891 |
-
Assert.True(csv.Read());
|
| 892 |
-
Assert.Equal("A\"\"B", csv.GetString(0));
|
| 893 |
-
Assert.Equal("Andmore", csv.GetString(1));
|
| 894 |
-
}
|
| 895 |
-
|
| 896 |
-
[Fact]
|
| 897 |
-
public void WhitespaceAsNull()
|
| 898 |
-
{
|
| 899 |
-
var schema = new TypedCsvSchema();
|
| 900 |
-
schema.Add(0, typeof(string));
|
| 901 |
-
schema.Add(1, typeof(int?));
|
| 902 |
-
|
| 903 |
-
using var tr = new StringReader("Name,Value\nA,1\nB, \nC,3");
|
| 904 |
-
var csv = CsvDataReader.Create(tr, new CsvDataReaderOptions { Schema = schema });
|
| 905 |
-
csv.Read();
|
| 906 |
-
Assert.False(csv.IsDBNull(1));
|
| 907 |
-
Assert.Equal(1, csv.GetInt32(1));
|
| 908 |
-
csv.Read();
|
| 909 |
-
Assert.True(csv.IsDBNull(1));
|
| 910 |
-
Assert.Throws<FormatException>(() => csv.GetInt32(1));
|
| 911 |
-
csv.Read();
|
| 912 |
-
Assert.False(csv.IsDBNull(1));
|
| 913 |
-
Assert.Equal(3, csv.GetInt32(1));
|
| 914 |
-
}
|
| 915 |
-
|
| 916 |
-
[Fact]
|
| 917 |
-
public void CultureWithCommaDecimal()
|
| 918 |
-
{
|
| 919 |
-
using var reader = new StringReader("Name;Value1;Value2\nTest;2,08;0,82\n");
|
| 920 |
-
|
| 921 |
-
var schema = Schema.Parse("Name,Value1:float,Value2:float");
|
| 922 |
-
|
| 923 |
-
var options = new CsvDataReaderOptions {
|
| 924 |
-
Schema = new CsvSchema(schema),
|
| 925 |
-
Culture = CultureInfo.GetCultureInfoByIetfLanguageTag("it-IT")
|
| 926 |
-
};
|
| 927 |
-
var csv = CsvDataReader.Create(reader, options);
|
| 928 |
-
var dt = new DataTable();
|
| 929 |
-
dt.Load(csv);
|
| 930 |
-
}
|
| 931 |
-
}
|
| 932 |
-
}
|
| 933 |
-
|
| 934 |
-
```
|
| 935 |
-
|
| 936 |
-
### Bug Type:
|
| 937 |
-
DOTNET_RESOURCE_LEAK
|
| 938 |
-
|
| 939 |
-
### Qualifier:
|
| 940 |
-
Leaked resource dt of type System.Data.DataTable in method "Void CsvDataReaderTests.CultureWithCommaDecimal()".
|
| 941 |
-
|
| 942 |
-
### Severity:
|
| 943 |
-
ERROR
|
| 944 |
-
|
| 945 |
-
### Procedure:
|
| 946 |
-
Void CsvDataReaderTests.CultureWithCommaDecimal()
|
| 947 |
-
|
| 948 |
-
### File:
|
| 949 |
-
source/Sylvan.Data.Csv.Tests/CsvDataReaderTests.cs
|
| 950 |
-
|
| 951 |
-
### Key:
|
| 952 |
-
CsvDataReaderTests.cs|CultureWithCommaDecimal|DOTNET_RESOURCE_LEAK
|
| 953 |
-
|
| 954 |
-
### Hash:
|
| 955 |
-
bb7a63ed6fa53b207833eb5dfd13e87b
|
| 956 |
-
|
| 957 |
-
### Bug Type Hum:
|
| 958 |
-
Dotnet Resource Leak
|
| 959 |
-
|
| 960 |
-
## Task
|
| 961 |
-
|
| 962 |
-
Analyze the bug information provided above. Your task is to:
|
| 963 |
-
|
| 964 |
-
1. **Understand the Bug**: Examine the buggy code and identify what the issue was
|
| 965 |
-
2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
|
| 966 |
-
3. **Evaluate the Fix**: Understand how the after code addresses the issue
|
| 967 |
-
4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
|
| 968 |
-
|
| 969 |
-
### Analysis Questions:
|
| 970 |
-
- What was the specific bug or issue in the original code?
|
| 971 |
-
- What scenarios would trigger this bug?
|
| 972 |
-
- How does the fix address the root cause?
|
| 973 |
-
- Are there any potential edge cases the fix might miss?
|
| 974 |
-
- What coding practices could have prevented this bug?
|
| 975 |
-
- Are there alternative ways to implement the fix?
|
| 976 |
-
|
| 977 |
-
Use the provided environment to explore, test, or reproduce the bug if needed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0007/instruction.md
DELETED
|
@@ -1,100 +0,0 @@
|
|
| 1 |
-
# InferredBugs Task - Csharp
|
| 2 |
-
|
| 3 |
-
## Project Information
|
| 4 |
-
|
| 5 |
-
**Project:** Sylvan
|
| 6 |
-
**Bug ID:** 2
|
| 7 |
-
**Language:** csharp
|
| 8 |
-
|
| 9 |
-
## Bug Information
|
| 10 |
-
|
| 11 |
-
### File-Level Changes:
|
| 12 |
-
|
| 13 |
-
**Before (Buggy File):**
|
| 14 |
-
```csharp
|
| 15 |
-
using BenchmarkDotNet.Attributes;
|
| 16 |
-
using BenchmarkDotNet.Jobs;
|
| 17 |
-
using Sylvan.IO;
|
| 18 |
-
using System.IO;
|
| 19 |
-
|
| 20 |
-
namespace Sylvan.Benchmarks
|
| 21 |
-
{
|
| 22 |
-
[SimpleJob(RuntimeMoniker.NetCoreApp31, launchCount: 1, warmupCount: 3, targetCount: 4)]
|
| 23 |
-
[MemoryDiagnoser]
|
| 24 |
-
public class MemoryStreamBenchmarks
|
| 25 |
-
{
|
| 26 |
-
const int Iterations = 100;
|
| 27 |
-
|
| 28 |
-
[Params(100, 500, 1000, 5000)]
|
| 29 |
-
public int Count { get; set; }
|
| 30 |
-
|
| 31 |
-
[Benchmark(Baseline = true)]
|
| 32 |
-
public void MemoryStream()
|
| 33 |
-
{
|
| 34 |
-
for (int i = 0; i < Iterations; i++)
|
| 35 |
-
{
|
| 36 |
-
using var stream = new MemoryStream(200);
|
| 37 |
-
Process(stream);
|
| 38 |
-
}
|
| 39 |
-
}
|
| 40 |
-
|
| 41 |
-
[Benchmark]
|
| 42 |
-
public void PooledMemoryStream()
|
| 43 |
-
{
|
| 44 |
-
for (int i = 0; i < Iterations; i++)
|
| 45 |
-
{
|
| 46 |
-
using var stream = new PooledMemoryStream();
|
| 47 |
-
Process(stream);
|
| 48 |
-
}
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
void Fill(Stream stream)
|
| 53 |
-
{
|
| 54 |
-
var tw = new StreamWriter(stream);
|
| 55 |
-
for (int i = 0; i < Count; i++)
|
| 56 |
-
{
|
| 57 |
-
tw.Write("This is a string");
|
| 58 |
-
tw.Write(12345);
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
-
stream.Seek(0, SeekOrigin.Begin);
|
| 62 |
-
}
|
| 63 |
-
|
| 64 |
-
void Process(Stream stream)
|
| 65 |
-
{
|
| 66 |
-
Fill(stream);
|
| 67 |
-
stream.CopyTo(Stream.Null);
|
| 68 |
-
}
|
| 69 |
-
}
|
| 70 |
-
}
|
| 71 |
-
|
| 72 |
-
```
|
| 73 |
-
|
| 74 |
-
### Bug Type:
|
| 75 |
-
DOTNET_RESOURCE_LEAK
|
| 76 |
-
|
| 77 |
-
### Qualifier:
|
| 78 |
-
Leaked resource tw of type System.IO.StreamWriter in method "Void MemoryStreamBenchmarks.Fill(Stream)".
|
| 79 |
-
|
| 80 |
-
### Severity:
|
| 81 |
-
ERROR
|
| 82 |
-
|
| 83 |
-
### Procedure:
|
| 84 |
-
Void MemoryStreamBenchmarks.Fill(Stream)
|
| 85 |
-
|
| 86 |
-
### File:
|
| 87 |
-
source/Sylvan.Benchmarks/MemoryStreamBenchmarks.cs
|
| 88 |
-
|
| 89 |
-
### Key:
|
| 90 |
-
MemoryStreamBenchmarks.cs|Fill|DOTNET_RESOURCE_LEAK
|
| 91 |
-
|
| 92 |
-
### Hash:
|
| 93 |
-
c41ac81b9922f3cf845fda1c223353e7
|
| 94 |
-
|
| 95 |
-
### Bug Type Hum:
|
| 96 |
-
Dotnet Resource Leak
|
| 97 |
-
|
| 98 |
-
## Task
|
| 99 |
-
|
| 100 |
-
Fix the bug in the code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0008/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0008/instruction.md
DELETED
|
@@ -1,81 +0,0 @@
|
|
| 1 |
-
# InferredBugs Task - Csharp
|
| 2 |
-
|
| 3 |
-
## Project Information
|
| 4 |
-
|
| 5 |
-
**Project:** OSS.Core
|
| 6 |
-
**Bug ID:** 1
|
| 7 |
-
**Language:** csharp
|
| 8 |
-
|
| 9 |
-
## Bug Information
|
| 10 |
-
|
| 11 |
-
### File-Level Changes:
|
| 12 |
-
|
| 13 |
-
**Before (Buggy File):**
|
| 14 |
-
```csharp
|
| 15 |
-
using System;
|
| 16 |
-
using System.Threading.Tasks;
|
| 17 |
-
using Microsoft.AspNetCore.Mvc.Filters;
|
| 18 |
-
using OSS.Core.Context;
|
| 19 |
-
|
| 20 |
-
namespace OSS.Core.Infrastructure.Web.Attributes.Auth
|
| 21 |
-
{
|
| 22 |
-
/// <summary>
|
| 23 |
-
/// 功能权限名称过滤器
|
| 24 |
-
/// </summary>
|
| 25 |
-
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
|
| 26 |
-
public class UserFuncAttribute : BaseOrderAuthAttribute
|
| 27 |
-
{
|
| 28 |
-
private readonly string _funcCode;
|
| 29 |
-
|
| 30 |
-
public UserFuncAttribute(string funcCode)
|
| 31 |
-
{
|
| 32 |
-
p_Order = -11;
|
| 33 |
-
_funcCode = funcCode;
|
| 34 |
-
}
|
| 35 |
-
|
| 36 |
-
public override Task OnAuthorizationAsync(AuthorizationFilterContext context)
|
| 37 |
-
{
|
| 38 |
-
var appIdentity = CoreAppContext.Identity;
|
| 39 |
-
if (string.IsNullOrEmpty(appIdentity.ask_func))
|
| 40 |
-
{
|
| 41 |
-
// 非需授权认证请求
|
| 42 |
-
appIdentity.ask_func = _funcCode;
|
| 43 |
-
}
|
| 44 |
-
return Task.CompletedTask;
|
| 45 |
-
}
|
| 46 |
-
|
| 47 |
-
}
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
```
|
| 51 |
-
|
| 52 |
-
### Bug Type:
|
| 53 |
-
NULL_DEREFERENCE
|
| 54 |
-
|
| 55 |
-
### Qualifier:
|
| 56 |
-
pointer `appIdentity` last assigned on line 24 could be null and is dereferenced at line 25, column 13.
|
| 57 |
-
|
| 58 |
-
### Severity:
|
| 59 |
-
ERROR
|
| 60 |
-
|
| 61 |
-
### Procedure:
|
| 62 |
-
Task UserFuncAttribute.OnAuthorizationAsync(AuthorizationFilterContext)
|
| 63 |
-
|
| 64 |
-
### File:
|
| 65 |
-
Common/OSS.Core.Infrastructure/OSS.Core.Infrastructure.Web/Attributes/Auth/UserFuncAttribute.cs
|
| 66 |
-
|
| 67 |
-
### Key:
|
| 68 |
-
UserFuncAttribute.cs|OnAuthorizationAsync|NULL_DEREFERENCE
|
| 69 |
-
|
| 70 |
-
### Node Key:
|
| 71 |
-
a35c6d97ccef7486c04c7fb208054b5b
|
| 72 |
-
|
| 73 |
-
### Hash:
|
| 74 |
-
47e90d6a4387e131bf1f28ac39d90f7e
|
| 75 |
-
|
| 76 |
-
### Bug Type Hum:
|
| 77 |
-
Null Dereference
|
| 78 |
-
|
| 79 |
-
## Task
|
| 80 |
-
|
| 81 |
-
Fix the bug in the code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0009/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0009/instruction.md
DELETED
|
@@ -1,142 +0,0 @@
|
|
| 1 |
-
# InferredBugs Task - Csharp
|
| 2 |
-
|
| 3 |
-
## Project Information
|
| 4 |
-
|
| 5 |
-
**Project:** OSS.Core
|
| 6 |
-
**Bug ID:** 4
|
| 7 |
-
**Language:** csharp
|
| 8 |
-
|
| 9 |
-
## Bug Information
|
| 10 |
-
|
| 11 |
-
### File-Level Changes:
|
| 12 |
-
|
| 13 |
-
**Before (Buggy File):**
|
| 14 |
-
```csharp
|
| 15 |
-
using System;
|
| 16 |
-
using System.Collections.Generic;
|
| 17 |
-
using System.IO;
|
| 18 |
-
using System.Text;
|
| 19 |
-
|
| 20 |
-
namespace OSSCore;
|
| 21 |
-
|
| 22 |
-
internal static class FileHelper
|
| 23 |
-
{
|
| 24 |
-
public static void CreateDirectory(string projectPath)
|
| 25 |
-
{
|
| 26 |
-
if (!Directory.Exists(projectPath))
|
| 27 |
-
{
|
| 28 |
-
Directory.CreateDirectory(projectPath);
|
| 29 |
-
}
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
-
public static void CreateProjectFile(string filePath, List<string> packageRefs, List<string> projectRefs,
|
| 33 |
-
bool isWeb = false)
|
| 34 |
-
{
|
| 35 |
-
var content = new StringBuilder();
|
| 36 |
-
|
| 37 |
-
content.AppendLine(isWeb ? "<Project Sdk=\"Microsoft.NET.Sdk.Web\">" : "<Project Sdk=\"Microsoft.NET.Sdk\">");
|
| 38 |
-
|
| 39 |
-
content.AppendLine(@"
|
| 40 |
-
<PropertyGroup>
|
| 41 |
-
<TargetFramework>net6.0</TargetFramework>
|
| 42 |
-
<ImplicitUsings>enable</ImplicitUsings>
|
| 43 |
-
<Nullable>enable</Nullable>
|
| 44 |
-
</PropertyGroup>");
|
| 45 |
-
|
| 46 |
-
if (packageRefs != null && packageRefs.Count > 0)
|
| 47 |
-
{
|
| 48 |
-
content.AppendLine(" <ItemGroup>");
|
| 49 |
-
foreach (var packageRef in packageRefs)
|
| 50 |
-
{
|
| 51 |
-
content.AppendLine($" <PackageReference Include=\"{packageRef}\" Version=\"*\"/>");
|
| 52 |
-
}
|
| 53 |
-
content.AppendLine(" </ItemGroup>");
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
if (projectRefs is {Count: > 0})
|
| 57 |
-
{
|
| 58 |
-
content.AppendLine(" <ItemGroup>");
|
| 59 |
-
foreach (var item in projectRefs)
|
| 60 |
-
{
|
| 61 |
-
content.AppendLine($" <ProjectReference Include=\"{item}\" />");
|
| 62 |
-
}
|
| 63 |
-
|
| 64 |
-
content.AppendLine(" </ItemGroup>");
|
| 65 |
-
}
|
| 66 |
-
|
| 67 |
-
content.AppendLine("</Project>");
|
| 68 |
-
|
| 69 |
-
CreateFile(filePath, content.ToString());
|
| 70 |
-
}
|
| 71 |
-
|
| 72 |
-
public static void CreateFile(string filePath, string fileContent)
|
| 73 |
-
{
|
| 74 |
-
if (File.Exists(filePath))
|
| 75 |
-
File.Delete(filePath);
|
| 76 |
-
|
| 77 |
-
using var sw = new StreamWriter(new FileStream(filePath, FileMode.Append, FileAccess.Write),
|
| 78 |
-
Encoding.UTF8);
|
| 79 |
-
sw.WriteLine(fileContent);
|
| 80 |
-
}
|
| 81 |
-
|
| 82 |
-
public static string LoadTemplateContent(SolutionStructure ss, string templateRelativePath)
|
| 83 |
-
{
|
| 84 |
-
var templatePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Templates", templateRelativePath);
|
| 85 |
-
string content;
|
| 86 |
-
|
| 87 |
-
using var file = new StreamReader(new FileStream(templatePath, FileMode.Open, FileAccess.Read));
|
| 88 |
-
{
|
| 89 |
-
content = file.ReadToEnd();
|
| 90 |
-
}
|
| 91 |
-
|
| 92 |
-
return content.Replace("{module_name}", ss.module_name)
|
| 93 |
-
.Replace("{solution_name}", ss.solution_name)
|
| 94 |
-
.Replace("{domain_project_name}", ss.domain_project.name)
|
| 95 |
-
.Replace("{domain_opened_project_name}", ss.domain_opened_project.name)
|
| 96 |
-
.Replace("{service_project_name}", ss.service_project.name)
|
| 97 |
-
.Replace("{service_opened_project_name}", ss.service_opened_project.name)
|
| 98 |
-
.Replace("{repository_project_name}", ss.rep_project.name)
|
| 99 |
-
.Replace("{webapi_project_name}", ss.webapi_project.name);
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
public static void CreateFileByTemplate(string filePath, SolutionStructure ss, string templateRelativePath)
|
| 104 |
-
{
|
| 105 |
-
var content = LoadTemplateContent(ss,templateRelativePath);
|
| 106 |
-
CreateFile(filePath, content);
|
| 107 |
-
}
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
}
|
| 114 |
-
```
|
| 115 |
-
|
| 116 |
-
### Bug Type:
|
| 117 |
-
DOTNET_RESOURCE_LEAK
|
| 118 |
-
|
| 119 |
-
### Qualifier:
|
| 120 |
-
Leaked resource (output of System.IO.FileStream::.ctor() at Line 73) of type System.IO.FileStream in method "String FileHelper.LoadTemplateContent(SolutionStructure,String)".
|
| 121 |
-
|
| 122 |
-
### Severity:
|
| 123 |
-
ERROR
|
| 124 |
-
|
| 125 |
-
### Procedure:
|
| 126 |
-
String FileHelper.LoadTemplateContent(SolutionStructure,String)
|
| 127 |
-
|
| 128 |
-
### File:
|
| 129 |
-
Framework/NetCli/OSS.Core.NetCli/Helper/FileHelper.cs
|
| 130 |
-
|
| 131 |
-
### Key:
|
| 132 |
-
FileHelper.cs|LoadTemplateContent|DOTNET_RESOURCE_LEAK
|
| 133 |
-
|
| 134 |
-
### Hash:
|
| 135 |
-
d4aa1f341ade39197def285bec52909f
|
| 136 |
-
|
| 137 |
-
### Bug Type Hum:
|
| 138 |
-
Dotnet Resource Leak
|
| 139 |
-
|
| 140 |
-
## Task
|
| 141 |
-
|
| 142 |
-
Fix the bug in the code.
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
inferredbugs-0010/instruction.md
DELETED
|
@@ -1,102 +0,0 @@
|
|
| 1 |
-
# InferredBugs Task - Csharp
|
| 2 |
-
|
| 3 |
-
## Project Information
|
| 4 |
-
|
| 5 |
-
**Project:** OSS.Core
|
| 6 |
-
**Bug ID:** 3
|
| 7 |
-
**Language:** csharp
|
| 8 |
-
|
| 9 |
-
## Bug Information
|
| 10 |
-
|
| 11 |
-
### File-Level Changes:
|
| 12 |
-
|
| 13 |
-
**Before (Buggy File):**
|
| 14 |
-
```csharp
|
| 15 |
-
using System;
|
| 16 |
-
using System.Threading.Tasks;
|
| 17 |
-
using Microsoft.AspNetCore.Http;
|
| 18 |
-
using OSS.Common.BasicMos.Resp;
|
| 19 |
-
using OSS.Common.Helpers;
|
| 20 |
-
using OSS.Core.Context;
|
| 21 |
-
using OSS.Core.Context.Attributes;
|
| 22 |
-
using OSS.Core.Infrastructure.Const;
|
| 23 |
-
using OSS.Core.Services.Basic.Portal.IProxies;
|
| 24 |
-
|
| 25 |
-
namespace OSS.Core.WebApi.App_Codes.AuthProviders
|
| 26 |
-
{
|
| 27 |
-
public class UserAuthProvider : IUserAuthProvider
|
| 28 |
-
{
|
| 29 |
-
public Task<Resp<UserIdentity>> GetIdentity(HttpContext context, AppIdentity appinfo)
|
| 30 |
-
{
|
| 31 |
-
return PortalAuthHelper.GetMyself(context.Request);
|
| 32 |
-
}
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
-
public class PortalAuthHelper
|
| 36 |
-
{
|
| 37 |
-
|
| 38 |
-
public static Task<Resp<UserIdentity>> GetMyself(HttpRequest req)
|
| 39 |
-
{
|
| 40 |
-
var appinfo = CoreAppContext.Identity;
|
| 41 |
-
if (appinfo.source_mode >= AppSourceMode.Browser)
|
| 42 |
-
{
|
| 43 |
-
appinfo.token = GetCookie(req);
|
| 44 |
-
}
|
| 45 |
-
return InsContainer<IPortalServiceProxy>.Instance.GetMyself();
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
public static void SetCookie(HttpResponse response, string token)
|
| 49 |
-
{
|
| 50 |
-
response.Cookies.Append(CoreCookieKeys.UserCookieName, token,
|
| 51 |
-
new CookieOptions() {
|
| 52 |
-
HttpOnly = true,
|
| 53 |
-
//SameSite = SameSiteMode.None,
|
| 54 |
-
//Secure = true,
|
| 55 |
-
Expires = DateTimeOffset.Now.AddDays(30)
|
| 56 |
-
});
|
| 57 |
-
}
|
| 58 |
-
|
| 59 |
-
public static string GetCookie(HttpRequest req)
|
| 60 |
-
{
|
| 61 |
-
return req.Cookies[CoreCookieKeys.UserCookieName];
|
| 62 |
-
}
|
| 63 |
-
|
| 64 |
-
public static void ClearCookie(HttpResponse response)
|
| 65 |
-
{
|
| 66 |
-
response.Cookies.Delete(CoreCookieKeys.UserCookieName);
|
| 67 |
-
}
|
| 68 |
-
}
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
```
|
| 72 |
-
|
| 73 |
-
### Bug Type:
|
| 74 |
-
NULL_DEREFERENCE
|
| 75 |
-
|
| 76 |
-
### Qualifier:
|
| 77 |
-
pointer `appinfo` last assigned on line 26 could be null and is dereferenced at line 27, column 13.
|
| 78 |
-
|
| 79 |
-
### Severity:
|
| 80 |
-
ERROR
|
| 81 |
-
|
| 82 |
-
### Procedure:
|
| 83 |
-
Task`1<!0> PortalAuthHelper.GetMyself(HttpRequest)
|
| 84 |
-
|
| 85 |
-
### File:
|
| 86 |
-
Apis/OSS.Core.WebApi/App_Codes/AuthProviders/UserAuthProvider.cs
|
| 87 |
-
|
| 88 |
-
### Key:
|
| 89 |
-
UserAuthProvider.cs|GetMyself|NULL_DEREFERENCE
|
| 90 |
-
|
| 91 |
-
### Node Key:
|
| 92 |
-
90535029835413c6e5d1bdebbf52bdf9
|
| 93 |
-
|
| 94 |
-
### Hash:
|
| 95 |
-
7ebe106742fec2446695e6ffcf53a7f1
|
| 96 |
-
|
| 97 |
-
### Bug Type Hum:
|
| 98 |
-
Null Dereference
|
| 99 |
-
|
| 100 |
-
## Task
|
| 101 |
-
|
| 102 |
-
Fix the bug in the code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0011/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0011/instruction.md
DELETED
|
@@ -1,102 +0,0 @@
|
|
| 1 |
-
# InferredBugs Task - Csharp
|
| 2 |
-
|
| 3 |
-
## Project Information
|
| 4 |
-
|
| 5 |
-
**Project:** OSS.Core
|
| 6 |
-
**Bug ID:** 2
|
| 7 |
-
**Language:** csharp
|
| 8 |
-
|
| 9 |
-
## Bug Information
|
| 10 |
-
|
| 11 |
-
### File-Level Changes:
|
| 12 |
-
|
| 13 |
-
**Before (Buggy File):**
|
| 14 |
-
```csharp
|
| 15 |
-
using System;
|
| 16 |
-
using System.Threading.Tasks;
|
| 17 |
-
using Microsoft.AspNetCore.Http;
|
| 18 |
-
using OSS.Common.BasicMos.Resp;
|
| 19 |
-
using OSS.Common.Helpers;
|
| 20 |
-
using OSS.Core.Context;
|
| 21 |
-
using OSS.Core.Infrastructure.Const;
|
| 22 |
-
using OSS.Core.Infrastructure.Web.Attributes.Auth.Interface;
|
| 23 |
-
using OSS.Core.Services.Basic.Portal.IProxies;
|
| 24 |
-
|
| 25 |
-
namespace OSS.Core.WebApi.App_Codes.AuthProviders
|
| 26 |
-
{
|
| 27 |
-
public class UserAuthProvider : IUserAuthProvider
|
| 28 |
-
{
|
| 29 |
-
public Task<Resp<UserIdentity>> GetIdentity(HttpContext context, AppIdentity appinfo)
|
| 30 |
-
{
|
| 31 |
-
return PortalAuthHelper.GetMyself(context.Request);
|
| 32 |
-
}
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
-
public class PortalAuthHelper
|
| 36 |
-
{
|
| 37 |
-
|
| 38 |
-
public static Task<Resp<UserIdentity>> GetMyself(HttpRequest req)
|
| 39 |
-
{
|
| 40 |
-
var appinfo = CoreAppContext.Identity;
|
| 41 |
-
if (appinfo.SourceMode >= AppSourceMode.BrowserWithHeader)
|
| 42 |
-
{
|
| 43 |
-
appinfo.token = GetCookie(req);
|
| 44 |
-
}
|
| 45 |
-
return InsContainer<IPortalServiceProxy>.Instance.GetMyself();
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
public static void SetCookie(HttpResponse response, string token)
|
| 49 |
-
{
|
| 50 |
-
response.Cookies.Append(CoreCookieKeys.UserCookieName, token,
|
| 51 |
-
new CookieOptions() {
|
| 52 |
-
HttpOnly = true,
|
| 53 |
-
//SameSite = SameSiteMode.None,
|
| 54 |
-
//Secure = true,
|
| 55 |
-
Expires = DateTimeOffset.Now.AddDays(30)
|
| 56 |
-
});
|
| 57 |
-
}
|
| 58 |
-
|
| 59 |
-
public static string GetCookie(HttpRequest req)
|
| 60 |
-
{
|
| 61 |
-
return req.Cookies[CoreCookieKeys.UserCookieName];
|
| 62 |
-
}
|
| 63 |
-
|
| 64 |
-
public static void ClearCookie(HttpResponse response)
|
| 65 |
-
{
|
| 66 |
-
response.Cookies.Delete(CoreCookieKeys.UserCookieName);
|
| 67 |
-
}
|
| 68 |
-
}
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
```
|
| 72 |
-
|
| 73 |
-
### Bug Type:
|
| 74 |
-
NULL_DEREFERENCE
|
| 75 |
-
|
| 76 |
-
### Qualifier:
|
| 77 |
-
pointer `appinfo` last assigned on line 26 could be null and is dereferenced at line 27, column 13.
|
| 78 |
-
|
| 79 |
-
### Severity:
|
| 80 |
-
ERROR
|
| 81 |
-
|
| 82 |
-
### Procedure:
|
| 83 |
-
Task`1<!0> PortalAuthHelper.GetMyself(HttpRequest)
|
| 84 |
-
|
| 85 |
-
### File:
|
| 86 |
-
Apis/OSS.Core.WebApi/App_Codes/AuthProviders/UserAuthProvider.cs
|
| 87 |
-
|
| 88 |
-
### Key:
|
| 89 |
-
UserAuthProvider.cs|GetMyself|NULL_DEREFERENCE
|
| 90 |
-
|
| 91 |
-
### Node Key:
|
| 92 |
-
90535029835413c6e5d1bdebbf52bdf9
|
| 93 |
-
|
| 94 |
-
### Hash:
|
| 95 |
-
7ebe106742fec2446695e6ffcf53a7f1
|
| 96 |
-
|
| 97 |
-
### Bug Type Hum:
|
| 98 |
-
Null Dereference
|
| 99 |
-
|
| 100 |
-
## Task
|
| 101 |
-
|
| 102 |
-
Fix the bug in the code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0012/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0012/instruction.md
DELETED
|
@@ -1,407 +0,0 @@
|
|
| 1 |
-
# InferredBugs Task - Csharp
|
| 2 |
-
|
| 3 |
-
## Project Information
|
| 4 |
-
|
| 5 |
-
**Project:** csredis
|
| 6 |
-
**Bug ID:** 1
|
| 7 |
-
**Language:** csharp
|
| 8 |
-
|
| 9 |
-
## Bug Information
|
| 10 |
-
|
| 11 |
-
### File-Level Changes:
|
| 12 |
-
|
| 13 |
-
**Before (Buggy File):**
|
| 14 |
-
```csharp
|
| 15 |
-
using CSRedis.Internal.IO;
|
| 16 |
-
using System;
|
| 17 |
-
using System.Collections.Concurrent;
|
| 18 |
-
using System.Collections.Generic;
|
| 19 |
-
using System.IO;
|
| 20 |
-
using System.Linq;
|
| 21 |
-
using System.Net;
|
| 22 |
-
using System.Net.Sockets;
|
| 23 |
-
using System.Text;
|
| 24 |
-
using System.Threading;
|
| 25 |
-
using System.Threading.Tasks;
|
| 26 |
-
|
| 27 |
-
namespace CSRedis.Internal
|
| 28 |
-
{
|
| 29 |
-
class RedisConnector : IRedisConnector
|
| 30 |
-
{
|
| 31 |
-
readonly DnsEndPoint _endpoint;
|
| 32 |
-
readonly SocketAsyncEventArgs _connectArgs; // TODO: lazy
|
| 33 |
-
readonly SocketAsyncPool _transferPool; // TODO: lazy
|
| 34 |
-
readonly ConcurrentQueue<IRedisAsyncCommandToken> _readQueue; // TODO: lazy
|
| 35 |
-
readonly ConcurrentQueue<IRedisAsyncCommandToken> _writeQueue; // TODO: lazy
|
| 36 |
-
readonly object _readLock;
|
| 37 |
-
readonly object _writeLock;
|
| 38 |
-
readonly RedisWriter _writer;
|
| 39 |
-
readonly RedisEncoding _encoding;
|
| 40 |
-
Socket _socket;
|
| 41 |
-
BufferedStream _stream;
|
| 42 |
-
RedisReader _reader;
|
| 43 |
-
RedisPipeline _pipeline;
|
| 44 |
-
bool _asyncConnectionStarted;
|
| 45 |
-
TaskCompletionSource<bool> _connectionTaskSource;
|
| 46 |
-
|
| 47 |
-
public event EventHandler Reconnected;
|
| 48 |
-
|
| 49 |
-
public bool Connected { get { return _socket == null ? false : _socket.Connected; } }
|
| 50 |
-
public string Host { get { return _endpoint.Host; } }
|
| 51 |
-
public int Port { get { return _endpoint.Port; } }
|
| 52 |
-
public bool Pipelined { get { return _pipeline.Active; } }
|
| 53 |
-
public int ReconnectAttempts { get; set; }
|
| 54 |
-
public int ReconnectWait { get; set; }
|
| 55 |
-
public int ReceiveTimeout
|
| 56 |
-
{
|
| 57 |
-
get { return _socket.ReceiveTimeout; }
|
| 58 |
-
set { _socket.ReceiveTimeout = value; }
|
| 59 |
-
}
|
| 60 |
-
public int SendTimeout
|
| 61 |
-
{
|
| 62 |
-
get { return _socket.SendTimeout; }
|
| 63 |
-
set { _socket.SendTimeout = value; }
|
| 64 |
-
}
|
| 65 |
-
public Encoding Encoding
|
| 66 |
-
{
|
| 67 |
-
get { return _encoding.Encoding; }
|
| 68 |
-
set { _encoding.Encoding = value; }
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
public RedisConnector(string host, int port, int concurrency, int bufferSize)
|
| 73 |
-
{
|
| 74 |
-
_endpoint = new DnsEndPoint(host, port);
|
| 75 |
-
_encoding = new RedisEncoding();
|
| 76 |
-
_transferPool = new SocketAsyncPool(concurrency, bufferSize);
|
| 77 |
-
_readQueue = new ConcurrentQueue<IRedisAsyncCommandToken>();
|
| 78 |
-
_writeQueue = new ConcurrentQueue<IRedisAsyncCommandToken>();
|
| 79 |
-
_readLock = new object();
|
| 80 |
-
_writeLock = new object();
|
| 81 |
-
_writer = new RedisWriter(_encoding);
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
_connectArgs = new SocketAsyncEventArgs { RemoteEndPoint = _endpoint };
|
| 85 |
-
_connectArgs.Completed += OnSocketCompleted;
|
| 86 |
-
_transferPool.Completed += OnSocketCompleted;
|
| 87 |
-
}
|
| 88 |
-
|
| 89 |
-
public bool Connect()
|
| 90 |
-
{
|
| 91 |
-
InitSocket();
|
| 92 |
-
_socket.Connect(_endpoint);
|
| 93 |
-
|
| 94 |
-
if (_socket.Connected)
|
| 95 |
-
InitReader();
|
| 96 |
-
|
| 97 |
-
return _socket.Connected;
|
| 98 |
-
}
|
| 99 |
-
|
| 100 |
-
public Task<bool> ConnectAsync()
|
| 101 |
-
{
|
| 102 |
-
if (!_asyncConnectionStarted && !Connected)
|
| 103 |
-
{
|
| 104 |
-
lock (_connectArgs)
|
| 105 |
-
{
|
| 106 |
-
if (!_asyncConnectionStarted && !Connected)
|
| 107 |
-
{
|
| 108 |
-
_asyncConnectionStarted = true;
|
| 109 |
-
InitSocket();
|
| 110 |
-
if (!_socket.ConnectAsync(_connectArgs))
|
| 111 |
-
OnSocketConnected(_connectArgs);
|
| 112 |
-
}
|
| 113 |
-
}
|
| 114 |
-
}
|
| 115 |
-
|
| 116 |
-
return _connectionTaskSource.Task;
|
| 117 |
-
}
|
| 118 |
-
|
| 119 |
-
public T Call<T>(RedisCommand<T> command)
|
| 120 |
-
{
|
| 121 |
-
ConnectIfNotConnected();
|
| 122 |
-
|
| 123 |
-
try
|
| 124 |
-
{
|
| 125 |
-
if (Pipelined)
|
| 126 |
-
return _pipeline.Write(command);
|
| 127 |
-
|
| 128 |
-
_writer.Write(command, _stream);
|
| 129 |
-
return command.Parse(_reader);
|
| 130 |
-
}
|
| 131 |
-
catch (IOException)
|
| 132 |
-
{
|
| 133 |
-
if (ReconnectAttempts == 0)
|
| 134 |
-
throw;
|
| 135 |
-
Reconnect();
|
| 136 |
-
return Call(command);
|
| 137 |
-
}
|
| 138 |
-
}
|
| 139 |
-
|
| 140 |
-
public Task<T> CallAsync<T>(RedisCommand<T> command)
|
| 141 |
-
{
|
| 142 |
-
var token = new RedisAsyncCommandToken<T>(command);
|
| 143 |
-
_writeQueue.Enqueue(token);
|
| 144 |
-
ConnectAsync().ContinueWith(CallAsyncDeferred);
|
| 145 |
-
return token.TaskSource.Task;
|
| 146 |
-
}
|
| 147 |
-
|
| 148 |
-
public void Write(RedisCommand command)
|
| 149 |
-
{
|
| 150 |
-
try
|
| 151 |
-
{
|
| 152 |
-
_writer.Write(command, _stream);
|
| 153 |
-
}
|
| 154 |
-
catch (IOException)
|
| 155 |
-
{
|
| 156 |
-
if (ReconnectAttempts == 0)
|
| 157 |
-
throw;
|
| 158 |
-
Reconnect();
|
| 159 |
-
Write(command);
|
| 160 |
-
}
|
| 161 |
-
}
|
| 162 |
-
|
| 163 |
-
public T Read<T>(Func<RedisReader, T> func)
|
| 164 |
-
{
|
| 165 |
-
try
|
| 166 |
-
{
|
| 167 |
-
return func(_reader);
|
| 168 |
-
}
|
| 169 |
-
catch (IOException)
|
| 170 |
-
{
|
| 171 |
-
if (ReconnectAttempts == 0)
|
| 172 |
-
throw;
|
| 173 |
-
Reconnect();
|
| 174 |
-
return Read(func);
|
| 175 |
-
}
|
| 176 |
-
}
|
| 177 |
-
|
| 178 |
-
public void Read(Stream destination, int bufferSize) // TODO: reconnect
|
| 179 |
-
{
|
| 180 |
-
try
|
| 181 |
-
{
|
| 182 |
-
_reader.ExpectType(RedisMessage.Bulk);
|
| 183 |
-
_reader.ReadBulk(destination, bufferSize, false);
|
| 184 |
-
}
|
| 185 |
-
catch (IOException)
|
| 186 |
-
{
|
| 187 |
-
if (ReconnectAttempts == 0)
|
| 188 |
-
throw;
|
| 189 |
-
Reconnect();
|
| 190 |
-
Read(destination, bufferSize);
|
| 191 |
-
}
|
| 192 |
-
}
|
| 193 |
-
|
| 194 |
-
public void BeginPipe()
|
| 195 |
-
{
|
| 196 |
-
ConnectIfNotConnected();
|
| 197 |
-
_pipeline.Begin();
|
| 198 |
-
}
|
| 199 |
-
|
| 200 |
-
public object[] EndPipe()
|
| 201 |
-
{
|
| 202 |
-
try
|
| 203 |
-
{
|
| 204 |
-
return _pipeline.Flush();
|
| 205 |
-
}
|
| 206 |
-
catch (IOException)
|
| 207 |
-
{
|
| 208 |
-
if (ReconnectAttempts == 0)
|
| 209 |
-
throw;
|
| 210 |
-
Reconnect();
|
| 211 |
-
return EndPipe();
|
| 212 |
-
}
|
| 213 |
-
}
|
| 214 |
-
|
| 215 |
-
public void Dispose()
|
| 216 |
-
{
|
| 217 |
-
_connectArgs.Dispose();
|
| 218 |
-
_transferPool.Dispose();
|
| 219 |
-
|
| 220 |
-
if (_pipeline != null)
|
| 221 |
-
_pipeline.Dispose();
|
| 222 |
-
|
| 223 |
-
if (_stream != null)
|
| 224 |
-
_stream.Dispose();
|
| 225 |
-
|
| 226 |
-
if (_socket != null)
|
| 227 |
-
_socket.Dispose();
|
| 228 |
-
|
| 229 |
-
}
|
| 230 |
-
|
| 231 |
-
void CallAsyncDeferred(Task t)
|
| 232 |
-
{
|
| 233 |
-
lock (_writeLock)
|
| 234 |
-
{
|
| 235 |
-
IRedisAsyncCommandToken token;
|
| 236 |
-
if (!_writeQueue.TryDequeue(out token))
|
| 237 |
-
throw new Exception();
|
| 238 |
-
|
| 239 |
-
_readQueue.Enqueue(token);
|
| 240 |
-
|
| 241 |
-
var args = _transferPool.Acquire();
|
| 242 |
-
int bytes;
|
| 243 |
-
try
|
| 244 |
-
{
|
| 245 |
-
bytes = _writer.Write(token.Command, args.Buffer, args.Offset);
|
| 246 |
-
}
|
| 247 |
-
catch (ArgumentException e)
|
| 248 |
-
{
|
| 249 |
-
throw new RedisClientException("Could not write command '" + token.Command.Command + "'. Argument size exceeds buffer allocation of " + args.Count + ".", e);
|
| 250 |
-
}
|
| 251 |
-
args.SetBuffer(args.Offset, bytes);
|
| 252 |
-
|
| 253 |
-
if (!_socket.SendAsync(args))
|
| 254 |
-
OnSocketSent(args);
|
| 255 |
-
}
|
| 256 |
-
}
|
| 257 |
-
|
| 258 |
-
void ConnectIfNotConnected()
|
| 259 |
-
{
|
| 260 |
-
if (!Connected)
|
| 261 |
-
Connect();
|
| 262 |
-
}
|
| 263 |
-
|
| 264 |
-
void Reconnect()
|
| 265 |
-
{
|
| 266 |
-
int attempts = 0;
|
| 267 |
-
while (attempts++ < ReconnectAttempts || ReconnectAttempts == -1)
|
| 268 |
-
{
|
| 269 |
-
if (Connect())
|
| 270 |
-
{
|
| 271 |
-
OnReconnected();
|
| 272 |
-
return;
|
| 273 |
-
}
|
| 274 |
-
|
| 275 |
-
Thread.Sleep(TimeSpan.FromMilliseconds(ReconnectWait));
|
| 276 |
-
}
|
| 277 |
-
|
| 278 |
-
throw new IOException("Could not reconnect after " + attempts + " attempts");
|
| 279 |
-
}
|
| 280 |
-
|
| 281 |
-
void OnSocketCompleted(object sender, SocketAsyncEventArgs e)
|
| 282 |
-
{
|
| 283 |
-
switch (e.LastOperation)
|
| 284 |
-
{
|
| 285 |
-
case SocketAsyncOperation.Connect:
|
| 286 |
-
OnSocketConnected(e);
|
| 287 |
-
break;
|
| 288 |
-
case SocketAsyncOperation.Send:
|
| 289 |
-
OnSocketSent(e);
|
| 290 |
-
break;
|
| 291 |
-
default:
|
| 292 |
-
throw new InvalidOperationException();
|
| 293 |
-
}
|
| 294 |
-
}
|
| 295 |
-
|
| 296 |
-
void OnSocketConnected(SocketAsyncEventArgs args)
|
| 297 |
-
{
|
| 298 |
-
if (_socket.Connected)
|
| 299 |
-
InitReader();
|
| 300 |
-
|
| 301 |
-
}
|
| 302 |
-
|
| 303 |
-
void OnSocketSent(SocketAsyncEventArgs args)
|
| 304 |
-
{
|
| 305 |
-
_transferPool.Release(args);
|
| 306 |
-
|
| 307 |
-
IRedisAsyncCommandToken token;
|
| 308 |
-
lock (_readLock)
|
| 309 |
-
{
|
| 310 |
-
if (_readQueue.TryDequeue(out token))
|
| 311 |
-
{
|
| 312 |
-
try
|
| 313 |
-
{
|
| 314 |
-
token.SetResult(_reader);
|
| 315 |
-
}
|
| 316 |
-
catch (IOException)
|
| 317 |
-
{
|
| 318 |
-
if (ReconnectAttempts == 0)
|
| 319 |
-
throw;
|
| 320 |
-
Reconnect();
|
| 321 |
-
_writeQueue.Enqueue(token);
|
| 322 |
-
ConnectAsync().ContinueWith(CallAsyncDeferred);
|
| 323 |
-
}
|
| 324 |
-
catch (Exception e)
|
| 325 |
-
{
|
| 326 |
-
token.SetException(e);
|
| 327 |
-
}
|
| 328 |
-
}
|
| 329 |
-
}
|
| 330 |
-
}
|
| 331 |
-
|
| 332 |
-
void OnReconnected()
|
| 333 |
-
{
|
| 334 |
-
if (Reconnected != null)
|
| 335 |
-
Reconnected(this, new EventArgs());
|
| 336 |
-
}
|
| 337 |
-
|
| 338 |
-
void InitSocket()
|
| 339 |
-
{
|
| 340 |
-
if (_socket != null)
|
| 341 |
-
_socket.Dispose();
|
| 342 |
-
if (_connectionTaskSource != null)
|
| 343 |
-
_connectionTaskSource.TrySetResult(false);
|
| 344 |
-
|
| 345 |
-
_connectionTaskSource = new TaskCompletionSource<bool>();
|
| 346 |
-
_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
| 347 |
-
}
|
| 348 |
-
|
| 349 |
-
void InitReader()
|
| 350 |
-
{
|
| 351 |
-
if (_stream != null)
|
| 352 |
-
_stream.Dispose();
|
| 353 |
-
|
| 354 |
-
_stream = new BufferedStream(new NetworkStream(_socket));
|
| 355 |
-
_reader = new RedisReader (_encoding, _stream);
|
| 356 |
-
_pipeline = new RedisPipeline(_stream, _encoding, _reader);
|
| 357 |
-
_connectionTaskSource.SetResult(_socket.Connected);
|
| 358 |
-
}
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
}
|
| 362 |
-
}
|
| 363 |
-
|
| 364 |
-
```
|
| 365 |
-
|
| 366 |
-
### Bug Type:
|
| 367 |
-
DOTNET_RESOURCE_LEAK
|
| 368 |
-
|
| 369 |
-
### Qualifier:
|
| 370 |
-
Leaked resource this.CSRedis.Internal.RedisConnector._pipeline of type CSRedis.Internal.RedisPipeline, Leaked resource (output of System.Net.Sockets.NetworkStream::.ctor() at Line 340) of type System.Net.Sockets.NetworkStream in method "Void RedisConnector.InitReader()".
|
| 371 |
-
|
| 372 |
-
### Severity:
|
| 373 |
-
ERROR
|
| 374 |
-
|
| 375 |
-
### Procedure:
|
| 376 |
-
Void RedisConnector.InitReader()
|
| 377 |
-
|
| 378 |
-
### File:
|
| 379 |
-
CSRedis/Internal/RedisConnector.cs
|
| 380 |
-
|
| 381 |
-
### Key:
|
| 382 |
-
RedisConnector.cs|InitReader|DOTNET_RESOURCE_LEAK
|
| 383 |
-
|
| 384 |
-
### Hash:
|
| 385 |
-
dc18d0828bf78dc02d47ab110de091d0
|
| 386 |
-
|
| 387 |
-
### Bug Type Hum:
|
| 388 |
-
Dotnet Resource Leak
|
| 389 |
-
|
| 390 |
-
## Task
|
| 391 |
-
|
| 392 |
-
Analyze the bug information provided above. Your task is to:
|
| 393 |
-
|
| 394 |
-
1. **Understand the Bug**: Examine the buggy code and identify what the issue was
|
| 395 |
-
2. **Analyze the Root Cause**: Determine why this bug occurred (logic error, edge case, etc.)
|
| 396 |
-
3. **Evaluate the Fix**: Understand how the after code addresses the issue
|
| 397 |
-
4. **Code Review**: Provide insights on code quality, potential improvements, and best practices
|
| 398 |
-
|
| 399 |
-
### Analysis Questions:
|
| 400 |
-
- What was the specific bug or issue in the original code?
|
| 401 |
-
- What scenarios would trigger this bug?
|
| 402 |
-
- How does the fix address the root cause?
|
| 403 |
-
- Are there any potential edge cases the fix might miss?
|
| 404 |
-
- What coding practices could have prevented this bug?
|
| 405 |
-
- Are there alternative ways to implement the fix?
|
| 406 |
-
|
| 407 |
-
Use the provided environment to explore, test, or reproduce the bug if needed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
|
|
|
inferredbugs-0013/instruction.md
DELETED
|
@@ -1,431 +0,0 @@
|
|
| 1 |
-
# InferredBugs Task - Csharp
|
| 2 |
-
|
| 3 |
-
## Project Information
|
| 4 |
-
|
| 5 |
-
**Project:** csredis
|
| 6 |
-
**Bug ID:** 3
|
| 7 |
-
**Language:** csharp
|
| 8 |
-
|
| 9 |
-
## Bug Information
|
| 10 |
-
|
| 11 |
-
### File-Level Changes:
|
| 12 |
-
|
| 13 |
-
**Before (Buggy File):**
|
| 14 |
-
```csharp
|
| 15 |
-
using CSRedis.Internal.IO;
|
| 16 |
-
using System;
|
| 17 |
-
using System.Collections.Concurrent;
|
| 18 |
-
using System.Collections.Generic;
|
| 19 |
-
using System.IO;
|
| 20 |
-
using System.Linq;
|
| 21 |
-
using System.Net;
|
| 22 |
-
using System.Net.Security;
|
| 23 |
-
using System.Net.Sockets;
|
| 24 |
-
using System.Text;
|
| 25 |
-
using System.Threading;
|
| 26 |
-
using System.Threading.Tasks;
|
| 27 |
-
|
| 28 |
-
namespace CSRedis.Internal
|
| 29 |
-
{
|
| 30 |
-
class RedisConnector : IRedisConnector
|
| 31 |
-
{
|
| 32 |
-
readonly DnsEndPoint _endpoint;
|
| 33 |
-
readonly Lazy<SocketAsyncEventArgs> _asyncConnectArgs;
|
| 34 |
-
readonly Lazy<SocketAsyncPool> _asyncTransferPool;
|
| 35 |
-
readonly Lazy<ConcurrentQueue<IRedisAsyncCommandToken>> _asyncReadQueue;
|
| 36 |
-
readonly Lazy<ConcurrentQueue<IRedisAsyncCommandToken>> _asyncWriteQueue;
|
| 37 |
-
readonly object _readLock;
|
| 38 |
-
readonly object _writeLock;
|
| 39 |
-
readonly RedisWriter _writer;
|
| 40 |
-
readonly RedisEncoding _encoding;
|
| 41 |
-
readonly int _concurrency;
|
| 42 |
-
readonly int _bufferSize;
|
| 43 |
-
readonly bool _ssl;
|
| 44 |
-
Socket _socket;
|
| 45 |
-
BufferedStream _stream;
|
| 46 |
-
RedisReader _reader;
|
| 47 |
-
RedisPipeline _pipeline;
|
| 48 |
-
bool _asyncConnectionStarted;
|
| 49 |
-
TaskCompletionSource<bool> _connectionTaskSource;
|
| 50 |
-
|
| 51 |
-
public event EventHandler Connected;
|
| 52 |
-
|
| 53 |
-
public bool IsConnected { get { return _socket == null ? false : _socket.Connected; } }
|
| 54 |
-
public string Host { get { return _endpoint.Host; } }
|
| 55 |
-
public int Port { get { return _endpoint.Port; } }
|
| 56 |
-
public bool IsPipelined { get { return _pipeline.Active; } }
|
| 57 |
-
public int ReconnectAttempts { get; set; }
|
| 58 |
-
public int ReconnectWait { get; set; }
|
| 59 |
-
public int ReceiveTimeout
|
| 60 |
-
{
|
| 61 |
-
get { return _socket.ReceiveTimeout; }
|
| 62 |
-
set { _socket.ReceiveTimeout = value; }
|
| 63 |
-
}
|
| 64 |
-
public int SendTimeout
|
| 65 |
-
{
|
| 66 |
-
get { return _socket.SendTimeout; }
|
| 67 |
-
set { _socket.SendTimeout = value; }
|
| 68 |
-
}
|
| 69 |
-
public Encoding Encoding
|
| 70 |
-
{
|
| 71 |
-
get { return _encoding.Encoding; }
|
| 72 |
-
set { _encoding.Encoding = value; }
|
| 73 |
-
}
|
| 74 |
-
SocketAsyncPool AsyncTransferPool { get { return _asyncTransferPool.Value; } }
|
| 75 |
-
SocketAsyncEventArgs AsyncConnectArgs { get { return _asyncConnectArgs.Value; } }
|
| 76 |
-
ConcurrentQueue<IRedisAsyncCommandToken> AsyncReadQueue { get { return _asyncReadQueue.Value; } }
|
| 77 |
-
ConcurrentQueue<IRedisAsyncCommandToken> AsyncWriteQueue { get { return _asyncWriteQueue.Value; } }
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
public RedisConnector(string host, int port, bool ssl, int concurrency, int bufferSize)
|
| 82 |
-
{
|
| 83 |
-
_concurrency = concurrency;
|
| 84 |
-
_bufferSize = bufferSize;
|
| 85 |
-
_endpoint = new DnsEndPoint(host, port);
|
| 86 |
-
_encoding = new RedisEncoding();
|
| 87 |
-
_asyncTransferPool = new Lazy<SocketAsyncPool>(SocketAsyncPoolFactory);
|
| 88 |
-
_asyncReadQueue = new Lazy<ConcurrentQueue<IRedisAsyncCommandToken>>(AsyncQueueFactory);
|
| 89 |
-
_asyncWriteQueue = new Lazy<ConcurrentQueue<IRedisAsyncCommandToken>>(AsyncQueueFactory);
|
| 90 |
-
_readLock = new object();
|
| 91 |
-
_writeLock = new object();
|
| 92 |
-
_writer = new RedisWriter(_encoding);
|
| 93 |
-
_asyncConnectArgs = new Lazy<SocketAsyncEventArgs>(SocketAsyncConnectFactory);
|
| 94 |
-
_ssl = ssl;
|
| 95 |
-
}
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
public bool Connect()
|
| 100 |
-
{
|
| 101 |
-
InitSocket();
|
| 102 |
-
_socket.Connect(_endpoint);
|
| 103 |
-
|
| 104 |
-
if (_socket.Connected)
|
| 105 |
-
InitReader();
|
| 106 |
-
|
| 107 |
-
return _socket.Connected;
|
| 108 |
-
}
|
| 109 |
-
|
| 110 |
-
public Task<bool> ConnectAsync()
|
| 111 |
-
{
|
| 112 |
-
if (!_asyncConnectionStarted && !IsConnected)
|
| 113 |
-
{
|
| 114 |
-
lock (_asyncConnectArgs)
|
| 115 |
-
{
|
| 116 |
-
if (!_asyncConnectionStarted && !IsConnected)
|
| 117 |
-
{
|
| 118 |
-
_asyncConnectionStarted = true;
|
| 119 |
-
InitSocket();
|
| 120 |
-
if (!_socket.ConnectAsync(AsyncConnectArgs))
|
| 121 |
-
OnSocketConnected(AsyncConnectArgs);
|
| 122 |
-
}
|
| 123 |
-
}
|
| 124 |
-
}
|
| 125 |
-
|
| 126 |
-
return _connectionTaskSource.Task;
|
| 127 |
-
}
|
| 128 |
-
|
| 129 |
-
public T Call<T>(RedisCommand<T> command)
|
| 130 |
-
{
|
| 131 |
-
ConnectIfNotConnected();
|
| 132 |
-
|
| 133 |
-
try
|
| 134 |
-
{
|
| 135 |
-
if (IsPipelined)
|
| 136 |
-
return _pipeline.Write(command);
|
| 137 |
-
|
| 138 |
-
_writer.Write(command, _stream);
|
| 139 |
-
return command.Parse(_reader);
|
| 140 |
-
}
|
| 141 |
-
catch (IOException)
|
| 142 |
-
{
|
| 143 |
-
if (ReconnectAttempts == 0)
|
| 144 |
-
throw;
|
| 145 |
-
Reconnect();
|
| 146 |
-
return Call(command);
|
| 147 |
-
}
|
| 148 |
-
}
|
| 149 |
-
|
| 150 |
-
public Task<T> CallAsync<T>(RedisCommand<T> command)
|
| 151 |
-
{
|
| 152 |
-
var token = new RedisAsyncCommandToken<T>(command);
|
| 153 |
-
AsyncWriteQueue.Enqueue(token);
|
| 154 |
-
ConnectAsync().ContinueWith(CallAsyncDeferred);
|
| 155 |
-
return token.TaskSource.Task;
|
| 156 |
-
}
|
| 157 |
-
|
| 158 |
-
public void Write(RedisCommand command)
|
| 159 |
-
{
|
| 160 |
-
try
|
| 161 |
-
{
|
| 162 |
-
_writer.Write(command, _stream);
|
| 163 |
-
}
|
| 164 |
-
catch (IOException)
|
| 165 |
-
{
|
| 166 |
-
if (ReconnectAttempts == 0)
|
| 167 |
-
throw;
|
| 168 |
-
Reconnect();
|
| 169 |
-
Write(command);
|
| 170 |
-
}
|
| 171 |
-
}
|
| 172 |
-
|
| 173 |
-
public T Read<T>(Func<RedisReader, T> func)
|
| 174 |
-
{
|
| 175 |
-
try
|
| 176 |
-
{
|
| 177 |
-
return func(_reader);
|
| 178 |
-
}
|
| 179 |
-
catch (IOException)
|
| 180 |
-
{
|
| 181 |
-
if (ReconnectAttempts == 0)
|
| 182 |
-
throw;
|
| 183 |
-
Reconnect();
|
| 184 |
-
return Read(func);
|
| 185 |
-
}
|
| 186 |
-
}
|
| 187 |
-
|
| 188 |
-
public void Read(Stream destination, int bufferSize) // TODO: reconnect
|
| 189 |
-
{
|
| 190 |
-
try
|
| 191 |
-
{
|
| 192 |
-
_reader.ExpectType(RedisMessage.Bulk);
|
| 193 |
-
_reader.ReadBulk(destination, bufferSize, false);
|
| 194 |
-
}
|
| 195 |
-
catch (IOException)
|
| 196 |
-
{
|
| 197 |
-
if (ReconnectAttempts == 0)
|
| 198 |
-
throw;
|
| 199 |
-
Reconnect();
|
| 200 |
-
Read(destination, bufferSize);
|
| 201 |
-
}
|
| 202 |
-
}
|
| 203 |
-
|
| 204 |
-
public void BeginPipe()
|
| 205 |
-
{
|
| 206 |
-
ConnectIfNotConnected();
|
| 207 |
-
_pipeline.Begin();
|
| 208 |
-
}
|
| 209 |
-
|
| 210 |
-
public object[] EndPipe()
|
| 211 |
-
{
|
| 212 |
-
try
|
| 213 |
-
{
|
| 214 |
-
return _pipeline.Flush();
|
| 215 |
-
}
|
| 216 |
-
catch (IOException)
|
| 217 |
-
{
|
| 218 |
-
if (ReconnectAttempts == 0)
|
| 219 |
-
throw;
|
| 220 |
-
Reconnect();
|
| 221 |
-
return EndPipe();
|
| 222 |
-
}
|
| 223 |
-
}
|
| 224 |
-
|
| 225 |
-
public void Dispose()
|
| 226 |
-
{
|
| 227 |
-
if (_asyncConnectArgs.IsValueCreated)
|
| 228 |
-
_asyncConnectArgs.Value.Dispose();
|
| 229 |
-
|
| 230 |
-
if (_asyncTransferPool.IsValueCreated)
|
| 231 |
-
_asyncTransferPool.Value.Dispose();
|
| 232 |
-
|
| 233 |
-
if (_pipeline != null)
|
| 234 |
-
_pipeline.Dispose();
|
| 235 |
-
|
| 236 |
-
if (_stream != null)
|
| 237 |
-
_stream.Dispose();
|
| 238 |
-
|
| 239 |
-
if (_socket != null)
|
| 240 |
-
_socket.Dispose();
|
| 241 |
-
|
| 242 |
-
}
|
| 243 |
-
|
| 244 |
-
void CallAsyncDeferred(Task t)
|
| 245 |
-
{
|
| 246 |
-
lock (_writeLock)
|
| 247 |
-
{
|
| 248 |
-
IRedisAsyncCommandToken token;
|
| 249 |
-
if (!AsyncWriteQueue.TryDequeue(out token))
|
| 250 |
-
throw new Exception();
|
| 251 |
-
|
| 252 |
-
AsyncReadQueue.Enqueue(token);
|
| 253 |
-
|
| 254 |
-
var args = AsyncTransferPool.Acquire();
|
| 255 |
-
int bytes;
|
| 256 |
-
try
|
| 257 |
-
{
|
| 258 |
-
bytes = _writer.Write(token.Command, args.Buffer, args.Offset);
|
| 259 |
-
}
|
| 260 |
-
catch (ArgumentException e)
|
| 261 |
-
{
|
| 262 |
-
throw new RedisClientException("Could not write command '" + token.Command.Command + "'. Argument size exceeds buffer allocation of " + args.Count + ".", e);
|
| 263 |
-
}
|
| 264 |
-
args.SetBuffer(args.Offset, bytes);
|
| 265 |
-
|
| 266 |
-
if (!_socket.SendAsync(args))
|
| 267 |
-
OnSocketSent(args);
|
| 268 |
-
}
|
| 269 |
-
}
|
| 270 |
-
|
| 271 |
-
void ConnectIfNotConnected()
|
| 272 |
-
{
|
| 273 |
-
if (!IsConnected)
|
| 274 |
-
Connect();
|
| 275 |
-
}
|
| 276 |
-
|
| 277 |
-
void Reconnect()
|
| 278 |
-
{
|
| 279 |
-
int attempts = 0;
|
| 280 |
-
while (attempts++ < ReconnectAttempts || ReconnectAttempts == -1)
|
| 281 |
-
{
|
| 282 |
-
if (Connect())
|
| 283 |
-
return;
|
| 284 |
-
|
| 285 |
-
Thread.Sleep(TimeSpan.FromMilliseconds(ReconnectWait));
|
| 286 |
-
}
|
| 287 |
-
|
| 288 |
-
throw new IOException("Could not reconnect after " + attempts + " attempts");
|
| 289 |
-
}
|
| 290 |
-
|
| 291 |
-
void OnSocketCompleted(object sender, SocketAsyncEventArgs e)
|
| 292 |
-
{
|
| 293 |
-
switch (e.LastOperation)
|
| 294 |
-
{
|
| 295 |
-
case SocketAsyncOperation.Connect:
|
| 296 |
-
OnSocketConnected(e);
|
| 297 |
-
break;
|
| 298 |
-
case SocketAsyncOperation.Send:
|
| 299 |
-
OnSocketSent(e);
|
| 300 |
-
break;
|
| 301 |
-
default:
|
| 302 |
-
throw new InvalidOperationException();
|
| 303 |
-
}
|
| 304 |
-
}
|
| 305 |
-
|
| 306 |
-
void OnSocketConnected(SocketAsyncEventArgs args)
|
| 307 |
-
{
|
| 308 |
-
if (_socket.Connected)
|
| 309 |
-
InitReader();
|
| 310 |
-
|
| 311 |
-
}
|
| 312 |
-
|
| 313 |
-
void OnSocketSent(SocketAsyncEventArgs args)
|
| 314 |
-
{
|
| 315 |
-
AsyncTransferPool.Release(args);
|
| 316 |
-
|
| 317 |
-
IRedisAsyncCommandToken token;
|
| 318 |
-
lock (_readLock)
|
| 319 |
-
{
|
| 320 |
-
if (AsyncReadQueue.TryDequeue(out token))
|
| 321 |
-
{
|
| 322 |
-
try
|
| 323 |
-
{
|
| 324 |
-
token.SetResult(_reader);
|
| 325 |
-
}
|
| 326 |
-
catch (IOException)
|
| 327 |
-
{
|
| 328 |
-
if (ReconnectAttempts == 0)
|
| 329 |
-
throw;
|
| 330 |
-
Reconnect();
|
| 331 |
-
AsyncWriteQueue.Enqueue(token);
|
| 332 |
-
ConnectAsync().ContinueWith(CallAsyncDeferred);
|
| 333 |
-
}
|
| 334 |
-
catch (Exception e)
|
| 335 |
-
{
|
| 336 |
-
token.SetException(e);
|
| 337 |
-
}
|
| 338 |
-
}
|
| 339 |
-
}
|
| 340 |
-
}
|
| 341 |
-
|
| 342 |
-
void OnConnected()
|
| 343 |
-
{
|
| 344 |
-
if (Connected != null)
|
| 345 |
-
Connected(this, new EventArgs());
|
| 346 |
-
}
|
| 347 |
-
|
| 348 |
-
void InitSocket()
|
| 349 |
-
{
|
| 350 |
-
if (_socket != null)
|
| 351 |
-
_socket.Dispose();
|
| 352 |
-
if (_connectionTaskSource != null)
|
| 353 |
-
_connectionTaskSource.TrySetResult(false);
|
| 354 |
-
|
| 355 |
-
_connectionTaskSource = new TaskCompletionSource<bool>();
|
| 356 |
-
_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
| 357 |
-
}
|
| 358 |
-
|
| 359 |
-
void InitReader()
|
| 360 |
-
{
|
| 361 |
-
if (_stream != null)
|
| 362 |
-
_stream.Dispose();
|
| 363 |
-
|
| 364 |
-
_stream = new BufferedStream(GetNetworkStream());
|
| 365 |
-
_reader = new RedisReader(_encoding, _stream);
|
| 366 |
-
_pipeline = new RedisPipeline(_stream, _encoding, _reader);
|
| 367 |
-
_connectionTaskSource.SetResult(_socket.Connected);
|
| 368 |
-
OnConnected();
|
| 369 |
-
}
|
| 370 |
-
|
| 371 |
-
Stream GetNetworkStream()
|
| 372 |
-
{
|
| 373 |
-
Stream netStream = new NetworkStream(_socket);
|
| 374 |
-
|
| 375 |
-
if (!_ssl) return netStream;
|
| 376 |
-
|
| 377 |
-
var sslStream = new SslStream(netStream, true);
|
| 378 |
-
sslStream.AuthenticateAsClient(_endpoint.Host);
|
| 379 |
-
return sslStream;
|
| 380 |
-
}
|
| 381 |
-
|
| 382 |
-
SocketAsyncPool SocketAsyncPoolFactory()
|
| 383 |
-
{
|
| 384 |
-
SocketAsyncPool pool = new SocketAsyncPool(_concurrency, _bufferSize);
|
| 385 |
-
pool.Completed += OnSocketCompleted;
|
| 386 |
-
return pool;
|
| 387 |
-
}
|
| 388 |
-
|
| 389 |
-
ConcurrentQueue<IRedisAsyncCommandToken> AsyncQueueFactory()
|
| 390 |
-
{
|
| 391 |
-
return new ConcurrentQueue<IRedisAsyncCommandToken>();
|
| 392 |
-
}
|
| 393 |
-
|
| 394 |
-
SocketAsyncEventArgs SocketAsyncConnectFactory()
|
| 395 |
-
{
|
| 396 |
-
SocketAsyncEventArgs args = new SocketAsyncEventArgs { RemoteEndPoint = _endpoint };
|
| 397 |
-
args.Completed += OnSocketCompleted;
|
| 398 |
-
return args;
|
| 399 |
-
}
|
| 400 |
-
}
|
| 401 |
-
}
|
| 402 |
-
|
| 403 |
-
```
|
| 404 |
-
|
| 405 |
-
### Bug Type:
|
| 406 |
-
DOTNET_RESOURCE_LEAK
|
| 407 |
-
|
| 408 |
-
### Qualifier:
|
| 409 |
-
Leaked resource this.CSRedis.Internal.RedisConnector._pipeline of type CSRedis.Internal.RedisPipeline in method "Void RedisConnector.InitReader()".
|
| 410 |
-
|
| 411 |
-
### Severity:
|
| 412 |
-
ERROR
|
| 413 |
-
|
| 414 |
-
### Procedure:
|
| 415 |
-
Void RedisConnector.InitReader()
|
| 416 |
-
|
| 417 |
-
### File:
|
| 418 |
-
CSRedis/Internal/RedisConnector.cs
|
| 419 |
-
|
| 420 |
-
### Key:
|
| 421 |
-
RedisConnector.cs|InitReader|DOTNET_RESOURCE_LEAK
|
| 422 |
-
|
| 423 |
-
### Hash:
|
| 424 |
-
f61e25cbba4f50ab0b943bd97fcd2b0a
|
| 425 |
-
|
| 426 |
-
### Bug Type Hum:
|
| 427 |
-
Dotnet Resource Leak
|
| 428 |
-
|
| 429 |
-
## Task
|
| 430 |
-
|
| 431 |
-
Fix the bug in the code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0014/instruction.md
DELETED
|
@@ -1,417 +0,0 @@
|
|
| 1 |
-
# InferredBugs Task - Csharp
|
| 2 |
-
|
| 3 |
-
## Project Information
|
| 4 |
-
|
| 5 |
-
**Project:** csredis
|
| 6 |
-
**Bug ID:** 2
|
| 7 |
-
**Language:** csharp
|
| 8 |
-
|
| 9 |
-
## Bug Information
|
| 10 |
-
|
| 11 |
-
### File-Level Changes:
|
| 12 |
-
|
| 13 |
-
**Before (Buggy File):**
|
| 14 |
-
```csharp
|
| 15 |
-
using CSRedis.Internal.IO;
|
| 16 |
-
using System;
|
| 17 |
-
using System.Collections.Concurrent;
|
| 18 |
-
using System.Collections.Generic;
|
| 19 |
-
using System.IO;
|
| 20 |
-
using System.Linq;
|
| 21 |
-
using System.Net;
|
| 22 |
-
using System.Net.Sockets;
|
| 23 |
-
using System.Text;
|
| 24 |
-
using System.Threading;
|
| 25 |
-
using System.Threading.Tasks;
|
| 26 |
-
|
| 27 |
-
namespace CSRedis.Internal
|
| 28 |
-
{
|
| 29 |
-
class RedisConnector : IRedisConnector
|
| 30 |
-
{
|
| 31 |
-
readonly DnsEndPoint _endpoint;
|
| 32 |
-
readonly Lazy<SocketAsyncEventArgs> _asyncConnectArgs;
|
| 33 |
-
readonly Lazy<SocketAsyncPool> _asyncTransferPool;
|
| 34 |
-
readonly Lazy<ConcurrentQueue<IRedisAsyncCommandToken>> _asyncReadQueue;
|
| 35 |
-
readonly Lazy<ConcurrentQueue<IRedisAsyncCommandToken>> _asyncWriteQueue;
|
| 36 |
-
readonly object _readLock;
|
| 37 |
-
readonly object _writeLock;
|
| 38 |
-
readonly RedisWriter _writer;
|
| 39 |
-
readonly RedisEncoding _encoding;
|
| 40 |
-
readonly int _concurrency;
|
| 41 |
-
readonly int _bufferSize;
|
| 42 |
-
Socket _socket;
|
| 43 |
-
BufferedStream _stream;
|
| 44 |
-
RedisReader _reader;
|
| 45 |
-
RedisPipeline _pipeline;
|
| 46 |
-
bool _asyncConnectionStarted;
|
| 47 |
-
TaskCompletionSource<bool> _connectionTaskSource;
|
| 48 |
-
|
| 49 |
-
public event EventHandler Connected;
|
| 50 |
-
|
| 51 |
-
public bool IsConnected { get { return _socket == null ? false : _socket.Connected; } }
|
| 52 |
-
public string Host { get { return _endpoint.Host; } }
|
| 53 |
-
public int Port { get { return _endpoint.Port; } }
|
| 54 |
-
public bool IsPipelined { get { return _pipeline.Active; } }
|
| 55 |
-
public int ReconnectAttempts { get; set; }
|
| 56 |
-
public int ReconnectWait { get; set; }
|
| 57 |
-
public int ReceiveTimeout
|
| 58 |
-
{
|
| 59 |
-
get { return _socket.ReceiveTimeout; }
|
| 60 |
-
set { _socket.ReceiveTimeout = value; }
|
| 61 |
-
}
|
| 62 |
-
public int SendTimeout
|
| 63 |
-
{
|
| 64 |
-
get { return _socket.SendTimeout; }
|
| 65 |
-
set { _socket.SendTimeout = value; }
|
| 66 |
-
}
|
| 67 |
-
public Encoding Encoding
|
| 68 |
-
{
|
| 69 |
-
get { return _encoding.Encoding; }
|
| 70 |
-
set { _encoding.Encoding = value; }
|
| 71 |
-
}
|
| 72 |
-
SocketAsyncPool AsyncTransferPool { get { return _asyncTransferPool.Value; } }
|
| 73 |
-
SocketAsyncEventArgs AsyncConnectArgs { get { return _asyncConnectArgs.Value; } }
|
| 74 |
-
ConcurrentQueue<IRedisAsyncCommandToken> AsyncReadQueue { get { return _asyncReadQueue.Value; } }
|
| 75 |
-
ConcurrentQueue<IRedisAsyncCommandToken> AsyncWriteQueue { get { return _asyncWriteQueue.Value; } }
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
public RedisConnector(string host, int port, int concurrency, int bufferSize)
|
| 80 |
-
{
|
| 81 |
-
_concurrency = concurrency;
|
| 82 |
-
_bufferSize = bufferSize;
|
| 83 |
-
_endpoint = new DnsEndPoint(host, port);
|
| 84 |
-
_encoding = new RedisEncoding();
|
| 85 |
-
_asyncTransferPool = new Lazy<SocketAsyncPool>(SocketAsyncPoolFactory);
|
| 86 |
-
_asyncReadQueue = new Lazy<ConcurrentQueue<IRedisAsyncCommandToken>>(AsyncQueueFactory);
|
| 87 |
-
_asyncWriteQueue = new Lazy<ConcurrentQueue<IRedisAsyncCommandToken>>(AsyncQueueFactory);
|
| 88 |
-
_readLock = new object();
|
| 89 |
-
_writeLock = new object();
|
| 90 |
-
_writer = new RedisWriter(_encoding);
|
| 91 |
-
_asyncConnectArgs = new Lazy<SocketAsyncEventArgs>(SocketAsyncConnectFactory);
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
public bool Connect()
|
| 97 |
-
{
|
| 98 |
-
InitSocket();
|
| 99 |
-
_socket.Connect(_endpoint);
|
| 100 |
-
|
| 101 |
-
if (_socket.Connected)
|
| 102 |
-
InitReader();
|
| 103 |
-
|
| 104 |
-
return _socket.Connected;
|
| 105 |
-
}
|
| 106 |
-
|
| 107 |
-
public Task<bool> ConnectAsync()
|
| 108 |
-
{
|
| 109 |
-
if (!_asyncConnectionStarted && !IsConnected)
|
| 110 |
-
{
|
| 111 |
-
lock (_asyncConnectArgs)
|
| 112 |
-
{
|
| 113 |
-
if (!_asyncConnectionStarted && !IsConnected)
|
| 114 |
-
{
|
| 115 |
-
_asyncConnectionStarted = true;
|
| 116 |
-
InitSocket();
|
| 117 |
-
if (!_socket.ConnectAsync(AsyncConnectArgs))
|
| 118 |
-
OnSocketConnected(AsyncConnectArgs);
|
| 119 |
-
}
|
| 120 |
-
}
|
| 121 |
-
}
|
| 122 |
-
|
| 123 |
-
return _connectionTaskSource.Task;
|
| 124 |
-
}
|
| 125 |
-
|
| 126 |
-
public T Call<T>(RedisCommand<T> command)
|
| 127 |
-
{
|
| 128 |
-
ConnectIfNotConnected();
|
| 129 |
-
|
| 130 |
-
try
|
| 131 |
-
{
|
| 132 |
-
if (IsPipelined)
|
| 133 |
-
return _pipeline.Write(command);
|
| 134 |
-
|
| 135 |
-
_writer.Write(command, _stream);
|
| 136 |
-
return command.Parse(_reader);
|
| 137 |
-
}
|
| 138 |
-
catch (IOException)
|
| 139 |
-
{
|
| 140 |
-
if (ReconnectAttempts == 0)
|
| 141 |
-
throw;
|
| 142 |
-
Reconnect();
|
| 143 |
-
return Call(command);
|
| 144 |
-
}
|
| 145 |
-
}
|
| 146 |
-
|
| 147 |
-
public Task<T> CallAsync<T>(RedisCommand<T> command)
|
| 148 |
-
{
|
| 149 |
-
var token = new RedisAsyncCommandToken<T>(command);
|
| 150 |
-
AsyncWriteQueue.Enqueue(token);
|
| 151 |
-
ConnectAsync().ContinueWith(CallAsyncDeferred);
|
| 152 |
-
return token.TaskSource.Task;
|
| 153 |
-
}
|
| 154 |
-
|
| 155 |
-
public void Write(RedisCommand command)
|
| 156 |
-
{
|
| 157 |
-
try
|
| 158 |
-
{
|
| 159 |
-
_writer.Write(command, _stream);
|
| 160 |
-
}
|
| 161 |
-
catch (IOException)
|
| 162 |
-
{
|
| 163 |
-
if (ReconnectAttempts == 0)
|
| 164 |
-
throw;
|
| 165 |
-
Reconnect();
|
| 166 |
-
Write(command);
|
| 167 |
-
}
|
| 168 |
-
}
|
| 169 |
-
|
| 170 |
-
public T Read<T>(Func<RedisReader, T> func)
|
| 171 |
-
{
|
| 172 |
-
try
|
| 173 |
-
{
|
| 174 |
-
return func(_reader);
|
| 175 |
-
}
|
| 176 |
-
catch (IOException)
|
| 177 |
-
{
|
| 178 |
-
if (ReconnectAttempts == 0)
|
| 179 |
-
throw;
|
| 180 |
-
Reconnect();
|
| 181 |
-
return Read(func);
|
| 182 |
-
}
|
| 183 |
-
}
|
| 184 |
-
|
| 185 |
-
public void Read(Stream destination, int bufferSize) // TODO: reconnect
|
| 186 |
-
{
|
| 187 |
-
try
|
| 188 |
-
{
|
| 189 |
-
_reader.ExpectType(RedisMessage.Bulk);
|
| 190 |
-
_reader.ReadBulk(destination, bufferSize, false);
|
| 191 |
-
}
|
| 192 |
-
catch (IOException)
|
| 193 |
-
{
|
| 194 |
-
if (ReconnectAttempts == 0)
|
| 195 |
-
throw;
|
| 196 |
-
Reconnect();
|
| 197 |
-
Read(destination, bufferSize);
|
| 198 |
-
}
|
| 199 |
-
}
|
| 200 |
-
|
| 201 |
-
public void BeginPipe()
|
| 202 |
-
{
|
| 203 |
-
ConnectIfNotConnected();
|
| 204 |
-
_pipeline.Begin();
|
| 205 |
-
}
|
| 206 |
-
|
| 207 |
-
public object[] EndPipe()
|
| 208 |
-
{
|
| 209 |
-
try
|
| 210 |
-
{
|
| 211 |
-
return _pipeline.Flush();
|
| 212 |
-
}
|
| 213 |
-
catch (IOException)
|
| 214 |
-
{
|
| 215 |
-
if (ReconnectAttempts == 0)
|
| 216 |
-
throw;
|
| 217 |
-
Reconnect();
|
| 218 |
-
return EndPipe();
|
| 219 |
-
}
|
| 220 |
-
}
|
| 221 |
-
|
| 222 |
-
public void Dispose()
|
| 223 |
-
{
|
| 224 |
-
if (_asyncConnectArgs.IsValueCreated)
|
| 225 |
-
_asyncConnectArgs.Value.Dispose();
|
| 226 |
-
|
| 227 |
-
if (_asyncTransferPool.IsValueCreated)
|
| 228 |
-
_asyncTransferPool.Value.Dispose();
|
| 229 |
-
|
| 230 |
-
if (_pipeline != null)
|
| 231 |
-
_pipeline.Dispose();
|
| 232 |
-
|
| 233 |
-
if (_stream != null)
|
| 234 |
-
_stream.Dispose();
|
| 235 |
-
|
| 236 |
-
if (_socket != null)
|
| 237 |
-
_socket.Dispose();
|
| 238 |
-
|
| 239 |
-
}
|
| 240 |
-
|
| 241 |
-
void CallAsyncDeferred(Task t)
|
| 242 |
-
{
|
| 243 |
-
lock (_writeLock)
|
| 244 |
-
{
|
| 245 |
-
IRedisAsyncCommandToken token;
|
| 246 |
-
if (!AsyncWriteQueue.TryDequeue(out token))
|
| 247 |
-
throw new Exception();
|
| 248 |
-
|
| 249 |
-
AsyncReadQueue.Enqueue(token);
|
| 250 |
-
|
| 251 |
-
var args = AsyncTransferPool.Acquire();
|
| 252 |
-
int bytes;
|
| 253 |
-
try
|
| 254 |
-
{
|
| 255 |
-
bytes = _writer.Write(token.Command, args.Buffer, args.Offset);
|
| 256 |
-
}
|
| 257 |
-
catch (ArgumentException e)
|
| 258 |
-
{
|
| 259 |
-
throw new RedisClientException("Could not write command '" + token.Command.Command + "'. Argument size exceeds buffer allocation of " + args.Count + ".", e);
|
| 260 |
-
}
|
| 261 |
-
args.SetBuffer(args.Offset, bytes);
|
| 262 |
-
|
| 263 |
-
if (!_socket.SendAsync(args))
|
| 264 |
-
OnSocketSent(args);
|
| 265 |
-
}
|
| 266 |
-
}
|
| 267 |
-
|
| 268 |
-
void ConnectIfNotConnected()
|
| 269 |
-
{
|
| 270 |
-
if (!IsConnected)
|
| 271 |
-
Connect();
|
| 272 |
-
}
|
| 273 |
-
|
| 274 |
-
void Reconnect()
|
| 275 |
-
{
|
| 276 |
-
int attempts = 0;
|
| 277 |
-
while (attempts++ < ReconnectAttempts || ReconnectAttempts == -1)
|
| 278 |
-
{
|
| 279 |
-
if (Connect())
|
| 280 |
-
return;
|
| 281 |
-
|
| 282 |
-
Thread.Sleep(TimeSpan.FromMilliseconds(ReconnectWait));
|
| 283 |
-
}
|
| 284 |
-
|
| 285 |
-
throw new IOException("Could not reconnect after " + attempts + " attempts");
|
| 286 |
-
}
|
| 287 |
-
|
| 288 |
-
void OnSocketCompleted(object sender, SocketAsyncEventArgs e)
|
| 289 |
-
{
|
| 290 |
-
switch (e.LastOperation)
|
| 291 |
-
{
|
| 292 |
-
case SocketAsyncOperation.Connect:
|
| 293 |
-
OnSocketConnected(e);
|
| 294 |
-
break;
|
| 295 |
-
case SocketAsyncOperation.Send:
|
| 296 |
-
OnSocketSent(e);
|
| 297 |
-
break;
|
| 298 |
-
default:
|
| 299 |
-
throw new InvalidOperationException();
|
| 300 |
-
}
|
| 301 |
-
}
|
| 302 |
-
|
| 303 |
-
void OnSocketConnected(SocketAsyncEventArgs args)
|
| 304 |
-
{
|
| 305 |
-
if (_socket.Connected)
|
| 306 |
-
InitReader();
|
| 307 |
-
|
| 308 |
-
}
|
| 309 |
-
|
| 310 |
-
void OnSocketSent(SocketAsyncEventArgs args)
|
| 311 |
-
{
|
| 312 |
-
AsyncTransferPool.Release(args);
|
| 313 |
-
|
| 314 |
-
IRedisAsyncCommandToken token;
|
| 315 |
-
lock (_readLock)
|
| 316 |
-
{
|
| 317 |
-
if (AsyncReadQueue.TryDequeue(out token))
|
| 318 |
-
{
|
| 319 |
-
try
|
| 320 |
-
{
|
| 321 |
-
token.SetResult(_reader);
|
| 322 |
-
}
|
| 323 |
-
catch (IOException)
|
| 324 |
-
{
|
| 325 |
-
if (ReconnectAttempts == 0)
|
| 326 |
-
throw;
|
| 327 |
-
Reconnect();
|
| 328 |
-
AsyncWriteQueue.Enqueue(token);
|
| 329 |
-
ConnectAsync().ContinueWith(CallAsyncDeferred);
|
| 330 |
-
}
|
| 331 |
-
catch (Exception e)
|
| 332 |
-
{
|
| 333 |
-
token.SetException(e);
|
| 334 |
-
}
|
| 335 |
-
}
|
| 336 |
-
}
|
| 337 |
-
}
|
| 338 |
-
|
| 339 |
-
void OnConnected()
|
| 340 |
-
{
|
| 341 |
-
if (Connected != null)
|
| 342 |
-
Connected(this, new EventArgs());
|
| 343 |
-
}
|
| 344 |
-
|
| 345 |
-
void InitSocket()
|
| 346 |
-
{
|
| 347 |
-
if (_socket != null)
|
| 348 |
-
_socket.Dispose();
|
| 349 |
-
if (_connectionTaskSource != null)
|
| 350 |
-
_connectionTaskSource.TrySetResult(false);
|
| 351 |
-
|
| 352 |
-
_connectionTaskSource = new TaskCompletionSource<bool>();
|
| 353 |
-
_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
| 354 |
-
}
|
| 355 |
-
|
| 356 |
-
void InitReader()
|
| 357 |
-
{
|
| 358 |
-
if (_stream != null)
|
| 359 |
-
_stream.Dispose();
|
| 360 |
-
|
| 361 |
-
_stream = new BufferedStream(new NetworkStream(_socket));
|
| 362 |
-
_reader = new RedisReader (_encoding, _stream);
|
| 363 |
-
_pipeline = new RedisPipeline(_stream, _encoding, _reader);
|
| 364 |
-
_connectionTaskSource.SetResult(_socket.Connected);
|
| 365 |
-
OnConnected();
|
| 366 |
-
}
|
| 367 |
-
|
| 368 |
-
SocketAsyncPool SocketAsyncPoolFactory()
|
| 369 |
-
{
|
| 370 |
-
SocketAsyncPool pool = new SocketAsyncPool(_concurrency, _bufferSize);
|
| 371 |
-
pool.Completed += OnSocketCompleted;
|
| 372 |
-
return pool;
|
| 373 |
-
}
|
| 374 |
-
|
| 375 |
-
ConcurrentQueue<IRedisAsyncCommandToken> AsyncQueueFactory()
|
| 376 |
-
{
|
| 377 |
-
return new ConcurrentQueue<IRedisAsyncCommandToken>();
|
| 378 |
-
}
|
| 379 |
-
|
| 380 |
-
SocketAsyncEventArgs SocketAsyncConnectFactory()
|
| 381 |
-
{
|
| 382 |
-
SocketAsyncEventArgs args = new SocketAsyncEventArgs { RemoteEndPoint = _endpoint };
|
| 383 |
-
args.Completed += OnSocketCompleted;
|
| 384 |
-
return args;
|
| 385 |
-
}
|
| 386 |
-
}
|
| 387 |
-
}
|
| 388 |
-
|
| 389 |
-
```
|
| 390 |
-
|
| 391 |
-
### Bug Type:
|
| 392 |
-
DOTNET_RESOURCE_LEAK
|
| 393 |
-
|
| 394 |
-
### Qualifier:
|
| 395 |
-
Leaked resource this.CSRedis.Internal.RedisConnector._pipeline of type CSRedis.Internal.RedisPipeline, Leaked resource (output of System.Net.Sockets.NetworkStream::.ctor() at Line 347) of type System.Net.Sockets.NetworkStream in method "Void RedisConnector.InitReader()".
|
| 396 |
-
|
| 397 |
-
### Severity:
|
| 398 |
-
ERROR
|
| 399 |
-
|
| 400 |
-
### Procedure:
|
| 401 |
-
Void RedisConnector.InitReader()
|
| 402 |
-
|
| 403 |
-
### File:
|
| 404 |
-
CSRedis/Internal/RedisConnector.cs
|
| 405 |
-
|
| 406 |
-
### Key:
|
| 407 |
-
RedisConnector.cs|InitReader|DOTNET_RESOURCE_LEAK
|
| 408 |
-
|
| 409 |
-
### Hash:
|
| 410 |
-
7ba00c378dc712781f66e2c7da1987dc
|
| 411 |
-
|
| 412 |
-
### Bug Type Hum:
|
| 413 |
-
Dotnet Resource Leak
|
| 414 |
-
|
| 415 |
-
## Task
|
| 416 |
-
|
| 417 |
-
Fix the bug in the code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0015/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0015/instruction.md
DELETED
|
@@ -1,119 +0,0 @@
|
|
| 1 |
-
# InferredBugs Task - Csharp
|
| 2 |
-
|
| 3 |
-
## Project Information
|
| 4 |
-
|
| 5 |
-
**Project:** Etl.Net
|
| 6 |
-
**Bug ID:** 1
|
| 7 |
-
**Language:** csharp
|
| 8 |
-
|
| 9 |
-
## Bug Information
|
| 10 |
-
|
| 11 |
-
### File-Level Changes:
|
| 12 |
-
|
| 13 |
-
**Before (Buggy File):**
|
| 14 |
-
```csharp
|
| 15 |
-
using Newtonsoft.Json;
|
| 16 |
-
using Paillave.Etl.Charts;
|
| 17 |
-
using Paillave.Etl.Core;
|
| 18 |
-
using System;
|
| 19 |
-
using System.Collections.Generic;
|
| 20 |
-
using System.Diagnostics;
|
| 21 |
-
using System.IO;
|
| 22 |
-
using System.Linq;
|
| 23 |
-
using System.Text;
|
| 24 |
-
using System.Threading.Tasks;
|
| 25 |
-
|
| 26 |
-
namespace Paillave.Etl
|
| 27 |
-
{
|
| 28 |
-
//http://resources.jointjs.com/demos/layout
|
| 29 |
-
public static partial class ExecutionContextEx
|
| 30 |
-
{
|
| 31 |
-
public static VisNetworkStatistics GetVisNetworkStatistics(this ExecutionStatus executionStatus)
|
| 32 |
-
{
|
| 33 |
-
var nameToIdDictionary = executionStatus.StreamToNodeLinks.Select(i => i.SourceNodeName).Union(executionStatus.StreamToNodeLinks.Select(i => i.TargetNodeName)).Distinct().Select((name, idx) => new { Name = name, Id = idx }).ToDictionary(i => i.Name, i => i.Id);
|
| 34 |
-
return new VisNetworkStatistics
|
| 35 |
-
{
|
| 36 |
-
edges = executionStatus.StreamToNodeLinks.GroupJoin(
|
| 37 |
-
executionStatus.StreamStatistics,
|
| 38 |
-
i => new
|
| 39 |
-
{
|
| 40 |
-
i.SourceNodeName,
|
| 41 |
-
i.StreamName
|
| 42 |
-
},
|
| 43 |
-
i => new
|
| 44 |
-
{
|
| 45 |
-
i.SourceNodeName,
|
| 46 |
-
i.StreamName
|
| 47 |
-
},
|
| 48 |
-
(link, stat) => new VisNetworkStatisticEdge
|
| 49 |
-
{
|
| 50 |
-
from = nameToIdDictionary[link.SourceNodeName],
|
| 51 |
-
to = nameToIdDictionary[link.TargetNodeName],
|
| 52 |
-
value = stat.DefaultIfEmpty(new StreamStatistic { Counter = 0 }).Sum(i => i.Counter)
|
| 53 |
-
}
|
| 54 |
-
).ToList(),
|
| 55 |
-
nodes = nameToIdDictionary.Select(i => new VisNetworkStatisticNode
|
| 56 |
-
{
|
| 57 |
-
id = i.Value,
|
| 58 |
-
label = i.Key
|
| 59 |
-
}).ToList()
|
| 60 |
-
};
|
| 61 |
-
}
|
| 62 |
-
public static string GetJsonVisNetworkStatistics(this ExecutionStatus executionStatus)
|
| 63 |
-
{
|
| 64 |
-
return JsonConvert.SerializeObject(executionStatus.GetVisNetworkStatistics());
|
| 65 |
-
}
|
| 66 |
-
public static string GetHtmlVisNetworkStatistics(this ExecutionStatus executionStatus)
|
| 67 |
-
{
|
| 68 |
-
var json = executionStatus.GetJsonVisNetworkStatistics();
|
| 69 |
-
string file;
|
| 70 |
-
|
| 71 |
-
var assembly = typeof(ExecutionContextEx).Assembly;
|
| 72 |
-
|
| 73 |
-
using (var stream = assembly.GetManifestResourceStream("Paillave.Etl.Charts.visnetworktemplate.html"))
|
| 74 |
-
using (var reader = new StreamReader(stream))
|
| 75 |
-
file = reader.ReadToEnd();
|
| 76 |
-
|
| 77 |
-
string html = file.Replace("'<<STATISTICS>>'", json);
|
| 78 |
-
return html;
|
| 79 |
-
}
|
| 80 |
-
public static void OpenVisNetworkStatistics(this ExecutionStatus executionStatus)
|
| 81 |
-
{
|
| 82 |
-
string tempFilePath = Path.GetTempFileName();
|
| 83 |
-
string htmlTempFilePath = Path.ChangeExtension(tempFilePath, "html");
|
| 84 |
-
File.Move(tempFilePath, htmlTempFilePath);
|
| 85 |
-
File.WriteAllText(htmlTempFilePath, executionStatus.GetHtmlVisNetworkStatistics());
|
| 86 |
-
new Process { StartInfo = new ProcessStartInfo(htmlTempFilePath) { UseShellExecute = true } }.Start();
|
| 87 |
-
}
|
| 88 |
-
}
|
| 89 |
-
}
|
| 90 |
-
|
| 91 |
-
```
|
| 92 |
-
|
| 93 |
-
### Bug Type:
|
| 94 |
-
DOTNET_RESOURCE_LEAK
|
| 95 |
-
|
| 96 |
-
### Qualifier:
|
| 97 |
-
Leaked resource (output of System.Diagnostics.Process::.ctor() at Line 72) of type System.Diagnostics.Process in method "Void ExecutionContextEx.OpenVisNetworkStatistics(ExecutionStatus)".
|
| 98 |
-
|
| 99 |
-
### Severity:
|
| 100 |
-
ERROR
|
| 101 |
-
|
| 102 |
-
### Procedure:
|
| 103 |
-
Void ExecutionContextEx.OpenVisNetworkStatistics(ExecutionStatus)
|
| 104 |
-
|
| 105 |
-
### File:
|
| 106 |
-
src/Paillave.Etl.Charts/ExecutionContext.VisNetwork.cs
|
| 107 |
-
|
| 108 |
-
### Key:
|
| 109 |
-
ExecutionContext.VisNetwork.cs|OpenVisNetworkStatistics|DOTNET_RESOURCE_LEAK
|
| 110 |
-
|
| 111 |
-
### Hash:
|
| 112 |
-
120b10d88744d4bd731a5c84ac86a66b
|
| 113 |
-
|
| 114 |
-
### Bug Type Hum:
|
| 115 |
-
Dotnet Resource Leak
|
| 116 |
-
|
| 117 |
-
## Task
|
| 118 |
-
|
| 119 |
-
Fix the bug in the code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0016/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0016/instruction.md
DELETED
|
@@ -1,119 +0,0 @@
|
|
| 1 |
-
# InferredBugs Task - Csharp
|
| 2 |
-
|
| 3 |
-
## Project Information
|
| 4 |
-
|
| 5 |
-
**Project:** Etl.Net
|
| 6 |
-
**Bug ID:** 3
|
| 7 |
-
**Language:** csharp
|
| 8 |
-
|
| 9 |
-
## Bug Information
|
| 10 |
-
|
| 11 |
-
### File-Level Changes:
|
| 12 |
-
|
| 13 |
-
**Before (Buggy File):**
|
| 14 |
-
```csharp
|
| 15 |
-
using Newtonsoft.Json;
|
| 16 |
-
using Paillave.Etl.Charts;
|
| 17 |
-
using Paillave.Etl.Core;
|
| 18 |
-
using System;
|
| 19 |
-
using System.Collections.Generic;
|
| 20 |
-
using System.Diagnostics;
|
| 21 |
-
using System.IO;
|
| 22 |
-
using System.Linq;
|
| 23 |
-
using System.Text;
|
| 24 |
-
using System.Threading.Tasks;
|
| 25 |
-
|
| 26 |
-
namespace Paillave.Etl
|
| 27 |
-
{
|
| 28 |
-
public static partial class ExecutionContextEx
|
| 29 |
-
{
|
| 30 |
-
public static D3SankeyStatistics GetD3SankeyStatistics(this ExecutionStatus executionStatus)
|
| 31 |
-
{
|
| 32 |
-
var nameToIdDictionary = executionStatus.StreamToNodeLinks.Select(i => i.SourceNodeName).Union(executionStatus.StreamToNodeLinks.Select(i => i.TargetNodeName)).Distinct().Select((name, idx) => new { Name = name, Id = idx }).ToDictionary(i => i.Name, i => i.Id);
|
| 33 |
-
return new D3SankeyStatistics
|
| 34 |
-
{
|
| 35 |
-
links = executionStatus.StreamToNodeLinks.GroupJoin(
|
| 36 |
-
executionStatus.StreamStatistics,
|
| 37 |
-
i => new
|
| 38 |
-
{
|
| 39 |
-
i.SourceNodeName,
|
| 40 |
-
i.StreamName
|
| 41 |
-
},
|
| 42 |
-
i => new
|
| 43 |
-
{
|
| 44 |
-
i.SourceNodeName,
|
| 45 |
-
i.StreamName
|
| 46 |
-
},
|
| 47 |
-
(link, stat) => new D3SankeyStatisticsLink
|
| 48 |
-
{
|
| 49 |
-
source = nameToIdDictionary[link.SourceNodeName],
|
| 50 |
-
target = nameToIdDictionary[link.TargetNodeName],
|
| 51 |
-
value = stat.DefaultIfEmpty(new StreamStatistic { Counter = 0 }).Sum(i => i.Counter)
|
| 52 |
-
}
|
| 53 |
-
).ToList(),
|
| 54 |
-
nodes = nameToIdDictionary.Select(i => new D3SankeyStatisticsNode
|
| 55 |
-
{
|
| 56 |
-
id = i.Value,
|
| 57 |
-
name = i.Key,
|
| 58 |
-
color = null
|
| 59 |
-
}).ToList()
|
| 60 |
-
};
|
| 61 |
-
}
|
| 62 |
-
public static string GetJsonD3SankeyStatistics(this ExecutionStatus executionStatus)
|
| 63 |
-
{
|
| 64 |
-
return JsonConvert.SerializeObject(executionStatus.GetD3SankeyStatistics());
|
| 65 |
-
}
|
| 66 |
-
public static string GetHtmlD3SankeyStatistics(this ExecutionStatus executionStatus)
|
| 67 |
-
{
|
| 68 |
-
var json = executionStatus.GetJsonD3SankeyStatistics();
|
| 69 |
-
string file;
|
| 70 |
-
|
| 71 |
-
var assembly = typeof(ExecutionContextEx).Assembly;
|
| 72 |
-
|
| 73 |
-
using (var stream = assembly.GetManifestResourceStream("Paillave.Etl.Charts.d3template.html"))
|
| 74 |
-
using (var reader = new StreamReader(stream))
|
| 75 |
-
file = reader.ReadToEnd();
|
| 76 |
-
|
| 77 |
-
string html = file.Replace("'<<SANKEY_STATISTICS>>'", json);
|
| 78 |
-
return html;
|
| 79 |
-
}
|
| 80 |
-
public static void OpenD3SankeyStatistics(this ExecutionStatus executionStatus)
|
| 81 |
-
{
|
| 82 |
-
string tempFilePath=Path.GetTempFileName();
|
| 83 |
-
string htmlTempFilePath = Path.ChangeExtension(tempFilePath, "html");
|
| 84 |
-
File.Move(tempFilePath, htmlTempFilePath);
|
| 85 |
-
File.WriteAllText(htmlTempFilePath, executionStatus.GetHtmlD3SankeyStatistics());
|
| 86 |
-
new Process { StartInfo = new ProcessStartInfo(htmlTempFilePath) { UseShellExecute = true } }.Start();
|
| 87 |
-
}
|
| 88 |
-
}
|
| 89 |
-
}
|
| 90 |
-
|
| 91 |
-
```
|
| 92 |
-
|
| 93 |
-
### Bug Type:
|
| 94 |
-
DOTNET_RESOURCE_LEAK
|
| 95 |
-
|
| 96 |
-
### Qualifier:
|
| 97 |
-
Leaked resource (output of System.Diagnostics.Process::.ctor() at Line 72) of type System.Diagnostics.Process in method "Void ExecutionContextEx.OpenD3SankeyStatistics(ExecutionStatus)".
|
| 98 |
-
|
| 99 |
-
### Severity:
|
| 100 |
-
ERROR
|
| 101 |
-
|
| 102 |
-
### Procedure:
|
| 103 |
-
Void ExecutionContextEx.OpenD3SankeyStatistics(ExecutionStatus)
|
| 104 |
-
|
| 105 |
-
### File:
|
| 106 |
-
src/Paillave.Etl.Charts/ExecutionContext.D3Sankey.cs
|
| 107 |
-
|
| 108 |
-
### Key:
|
| 109 |
-
ExecutionContext.D3Sankey.cs|OpenD3SankeyStatistics|DOTNET_RESOURCE_LEAK
|
| 110 |
-
|
| 111 |
-
### Hash:
|
| 112 |
-
764a0baeca1cb2126bb627882b69a76e
|
| 113 |
-
|
| 114 |
-
### Bug Type Hum:
|
| 115 |
-
Dotnet Resource Leak
|
| 116 |
-
|
| 117 |
-
## Task
|
| 118 |
-
|
| 119 |
-
Fix the bug in the code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0017/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0017/instruction.md
DELETED
|
@@ -1,122 +0,0 @@
|
|
| 1 |
-
# InferredBugs Task - Csharp
|
| 2 |
-
|
| 3 |
-
## Project Information
|
| 4 |
-
|
| 5 |
-
**Project:** Etl.Net
|
| 6 |
-
**Bug ID:** 2
|
| 7 |
-
**Language:** csharp
|
| 8 |
-
|
| 9 |
-
## Bug Information
|
| 10 |
-
|
| 11 |
-
### File-Level Changes:
|
| 12 |
-
|
| 13 |
-
**Before (Buggy File):**
|
| 14 |
-
```csharp
|
| 15 |
-
using Newtonsoft.Json;
|
| 16 |
-
using Paillave.Etl.Charts;
|
| 17 |
-
using Paillave.Etl.Core;
|
| 18 |
-
using System;
|
| 19 |
-
using System.Collections.Generic;
|
| 20 |
-
using System.Diagnostics;
|
| 21 |
-
using System.IO;
|
| 22 |
-
using System.Linq;
|
| 23 |
-
using System.Text;
|
| 24 |
-
using System.Threading.Tasks;
|
| 25 |
-
|
| 26 |
-
namespace Paillave.Etl
|
| 27 |
-
{
|
| 28 |
-
public static partial class ExecutionContextEx
|
| 29 |
-
{
|
| 30 |
-
public static PlotlySankeyStatistics GetPlotlySankeyStatistics(this ExecutionStatus executionStatus)
|
| 31 |
-
{
|
| 32 |
-
var nameToIdDictionary = executionStatus.StreamToNodeLinks.Select(i => i.SourceNodeName).Union(executionStatus.StreamToNodeLinks.Select(i => i.TargetNodeName)).Distinct().Select((name, idx) => new { Name = name, Id = idx }).ToDictionary(i => i.Name, i => i.Id);
|
| 33 |
-
var links = executionStatus.StreamToNodeLinks.GroupJoin(
|
| 34 |
-
executionStatus.StreamStatistics,
|
| 35 |
-
i => new
|
| 36 |
-
{
|
| 37 |
-
i.SourceNodeName,
|
| 38 |
-
i.StreamName
|
| 39 |
-
},
|
| 40 |
-
i => new
|
| 41 |
-
{
|
| 42 |
-
i.SourceNodeName,
|
| 43 |
-
i.StreamName
|
| 44 |
-
},
|
| 45 |
-
(link, stat) => new
|
| 46 |
-
{
|
| 47 |
-
source = nameToIdDictionary[link.SourceNodeName],
|
| 48 |
-
target = nameToIdDictionary[link.TargetNodeName],
|
| 49 |
-
value = stat.DefaultIfEmpty(new StreamStatistic { Counter = 0 }).Sum(i => i.Counter)
|
| 50 |
-
}
|
| 51 |
-
).ToList();
|
| 52 |
-
return new PlotlySankeyStatistics
|
| 53 |
-
{
|
| 54 |
-
NodeColors = nameToIdDictionary.OrderBy(i => i.Value).Select(i => "blue").ToList(),
|
| 55 |
-
NodeNames = nameToIdDictionary.OrderBy(i => i.Value).Select(i => i.Key).ToList(),
|
| 56 |
-
LinkSources = links.Select(i => i.source).ToList(),
|
| 57 |
-
LinkTargets = links.Select(i => i.target).ToList(),
|
| 58 |
-
LinkValues = links.Select(i => i.value).ToList()
|
| 59 |
-
};
|
| 60 |
-
}
|
| 61 |
-
//public static async Task<string> GetJsonPlotlySankeyStatisticsAsync<T>(this ExecutionContext<T> executionStatus)
|
| 62 |
-
//{
|
| 63 |
-
// return JsonConvert.SerializeObject(await executionStatus.GetPlotlySankeyStatisticsAsync());
|
| 64 |
-
//}
|
| 65 |
-
public static string GetHtmlPlotlySankeyStatistics(this ExecutionStatus executionStatus)
|
| 66 |
-
{
|
| 67 |
-
var stats = executionStatus.GetPlotlySankeyStatistics();
|
| 68 |
-
string file;
|
| 69 |
-
|
| 70 |
-
var assembly = typeof(ExecutionContextEx).Assembly;
|
| 71 |
-
|
| 72 |
-
using (var stream = assembly.GetManifestResourceStream("Paillave.Etl.Charts.plotlytemplate.html"))
|
| 73 |
-
using (var reader = new StreamReader(stream))
|
| 74 |
-
file = reader.ReadToEnd();
|
| 75 |
-
|
| 76 |
-
string html = file.Replace("'<<NODE_NAMES>>'", JsonConvert.SerializeObject(stats.NodeNames));
|
| 77 |
-
html = html.Replace("'<<NODE_COLORS>>'", JsonConvert.SerializeObject(stats.NodeColors));
|
| 78 |
-
html = html.Replace("'<<LINK_SOURCES>>'", JsonConvert.SerializeObject(stats.LinkSources));
|
| 79 |
-
html = html.Replace("'<<LINK_TARGETS>>'", JsonConvert.SerializeObject(stats.LinkTargets));
|
| 80 |
-
html = html.Replace("'<<LINK_VALUES>>'", JsonConvert.SerializeObject(stats.LinkValues));
|
| 81 |
-
return html;
|
| 82 |
-
}
|
| 83 |
-
public static void OpenPlotlySankeyStatistics(this ExecutionStatus executionStatus)
|
| 84 |
-
{
|
| 85 |
-
string tempFilePath = Path.GetTempFileName();
|
| 86 |
-
string htmlTempFilePath = Path.ChangeExtension(tempFilePath, "html");
|
| 87 |
-
File.Move(tempFilePath, htmlTempFilePath);
|
| 88 |
-
File.WriteAllText(htmlTempFilePath, executionStatus.GetHtmlPlotlySankeyStatistics());
|
| 89 |
-
new Process { StartInfo = new ProcessStartInfo(htmlTempFilePath) { UseShellExecute = true } }.Start();
|
| 90 |
-
}
|
| 91 |
-
}
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
```
|
| 95 |
-
|
| 96 |
-
### Bug Type:
|
| 97 |
-
DOTNET_RESOURCE_LEAK
|
| 98 |
-
|
| 99 |
-
### Qualifier:
|
| 100 |
-
Leaked resource (output of System.Diagnostics.Process::.ctor() at Line 75) of type System.Diagnostics.Process in method "Void ExecutionContextEx.OpenPlotlySankeyStatistics(ExecutionStatus)".
|
| 101 |
-
|
| 102 |
-
### Severity:
|
| 103 |
-
ERROR
|
| 104 |
-
|
| 105 |
-
### Procedure:
|
| 106 |
-
Void ExecutionContextEx.OpenPlotlySankeyStatistics(ExecutionStatus)
|
| 107 |
-
|
| 108 |
-
### File:
|
| 109 |
-
src/Paillave.Etl.Charts/ExecutionContext.PlotySankey.cs
|
| 110 |
-
|
| 111 |
-
### Key:
|
| 112 |
-
ExecutionContext.PlotySankey.cs|OpenPlotlySankeyStatistics|DOTNET_RESOURCE_LEAK
|
| 113 |
-
|
| 114 |
-
### Hash:
|
| 115 |
-
da6a03043313aaa006a5f73e0f798e86
|
| 116 |
-
|
| 117 |
-
### Bug Type Hum:
|
| 118 |
-
Dotnet Resource Leak
|
| 119 |
-
|
| 120 |
-
## Task
|
| 121 |
-
|
| 122 |
-
Fix the bug in the code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0018/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0018/instruction.md
DELETED
|
@@ -1,156 +0,0 @@
|
|
| 1 |
-
# InferredBugs Task - Csharp
|
| 2 |
-
|
| 3 |
-
## Project Information
|
| 4 |
-
|
| 5 |
-
**Project:** Newtonsoft.Json.Schema
|
| 6 |
-
**Bug ID:** 1
|
| 7 |
-
**Language:** csharp
|
| 8 |
-
|
| 9 |
-
## Bug Information
|
| 10 |
-
|
| 11 |
-
### File-Level Changes:
|
| 12 |
-
|
| 13 |
-
**Before (Buggy File):**
|
| 14 |
-
```csharp
|
| 15 |
-
#region License
|
| 16 |
-
// Copyright (c) Newtonsoft. All Rights Reserved.
|
| 17 |
-
// License: https://raw.github.com/JamesNK/Newtonsoft.Json.Schema/master/LICENSE.md
|
| 18 |
-
#endregion
|
| 19 |
-
|
| 20 |
-
using System;
|
| 21 |
-
using System.Collections.Generic;
|
| 22 |
-
using System.Diagnostics;
|
| 23 |
-
using System.Globalization;
|
| 24 |
-
using System.Linq;
|
| 25 |
-
|
| 26 |
-
namespace Newtonsoft.Json.Schema.Infrastructure.Validation
|
| 27 |
-
{
|
| 28 |
-
internal sealed class IfThenElseScope : ConditionalScope
|
| 29 |
-
{
|
| 30 |
-
public ConditionalContext? ThenContext;
|
| 31 |
-
public ConditionalContext? ElseContext;
|
| 32 |
-
|
| 33 |
-
public JSchema? If;
|
| 34 |
-
public JSchema? Then;
|
| 35 |
-
public JSchema? Else;
|
| 36 |
-
|
| 37 |
-
public override void Initialize(ContextBase context, SchemaScope? parent, int initialDepth, ScopeType type)
|
| 38 |
-
{
|
| 39 |
-
base.Initialize(context, parent, initialDepth, type);
|
| 40 |
-
|
| 41 |
-
If = null;
|
| 42 |
-
Then = null;
|
| 43 |
-
Else = null;
|
| 44 |
-
|
| 45 |
-
ThenContext = null;
|
| 46 |
-
ElseContext = null;
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
protected override bool EvaluateTokenCore(JsonToken token, object? value, int depth)
|
| 50 |
-
{
|
| 51 |
-
SchemaScope ifScope = GetSchemaScopeBySchema(If!, token, value, depth)!;
|
| 52 |
-
|
| 53 |
-
if (ifScope.IsValid)
|
| 54 |
-
{
|
| 55 |
-
ConditionalContext.TrackEvaluatedSchema(ifScope.Schema);
|
| 56 |
-
|
| 57 |
-
if (Then != null)
|
| 58 |
-
{
|
| 59 |
-
SchemaScope thenScope = GetSchemaScopeBySchema(Then, token, value, depth)!;
|
| 60 |
-
|
| 61 |
-
if (!thenScope.IsValid)
|
| 62 |
-
{
|
| 63 |
-
RaiseError($"JSON does not match schema from 'then'.", ErrorType.Then, Then, null, thenScope.GetValidationErrors());
|
| 64 |
-
}
|
| 65 |
-
else
|
| 66 |
-
{
|
| 67 |
-
ConditionalContext.TrackEvaluatedSchema(thenScope.Schema);
|
| 68 |
-
}
|
| 69 |
-
}
|
| 70 |
-
}
|
| 71 |
-
else
|
| 72 |
-
{
|
| 73 |
-
if (Else != null)
|
| 74 |
-
{
|
| 75 |
-
SchemaScope elseScope = GetSchemaScopeBySchema(Else, token, value, depth)!;
|
| 76 |
-
|
| 77 |
-
if (!elseScope.IsValid)
|
| 78 |
-
{
|
| 79 |
-
RaiseError($"JSON does not match schema from 'else'.", ErrorType.Else, Else, null, elseScope.GetValidationErrors());
|
| 80 |
-
}
|
| 81 |
-
else
|
| 82 |
-
{
|
| 83 |
-
ConditionalContext.TrackEvaluatedSchema(elseScope.Schema);
|
| 84 |
-
}
|
| 85 |
-
}
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
return true;
|
| 89 |
-
}
|
| 90 |
-
|
| 91 |
-
public void InitializeScopes(JsonToken token, int scopeIndex)
|
| 92 |
-
{
|
| 93 |
-
InitializeScope(token, scopeIndex, If!, ConditionalContext);
|
| 94 |
-
if (Then != null)
|
| 95 |
-
{
|
| 96 |
-
InitializeScope(token, scopeIndex, Then, ThenContext!);
|
| 97 |
-
}
|
| 98 |
-
if (Else != null)
|
| 99 |
-
{
|
| 100 |
-
InitializeScope(token, scopeIndex, Else, ElseContext!);
|
| 101 |
-
}
|
| 102 |
-
}
|
| 103 |
-
|
| 104 |
-
private void InitializeScope(JsonToken token, int scopeIndex, JSchema schema, ConditionalContext context)
|
| 105 |
-
{
|
| 106 |
-
// cache this for performance
|
| 107 |
-
int scopeCurrentIndex = scopeIndex;
|
| 108 |
-
|
| 109 |
-
// check to see whether a scope with the same schema exists
|
| 110 |
-
SchemaScope? childScope = GetExistingSchemaScope(schema, ref scopeCurrentIndex);
|
| 111 |
-
|
| 112 |
-
if (childScope == null)
|
| 113 |
-
{
|
| 114 |
-
childScope = SchemaScope.CreateTokenScope(token, schema, context, null, InitialDepth);
|
| 115 |
-
}
|
| 116 |
-
|
| 117 |
-
#if DEBUG
|
| 118 |
-
childScope.ConditionalParents.Add(this);
|
| 119 |
-
#endif
|
| 120 |
-
|
| 121 |
-
ChildScopes.Add(childScope);
|
| 122 |
-
}
|
| 123 |
-
}
|
| 124 |
-
}
|
| 125 |
-
```
|
| 126 |
-
|
| 127 |
-
### Bug Type:
|
| 128 |
-
NULL_DEREFERENCE
|
| 129 |
-
|
| 130 |
-
### Qualifier:
|
| 131 |
-
pointer `elseScope` last assigned on line 61 could be null and is dereferenced at line 63, column 21.
|
| 132 |
-
|
| 133 |
-
### Severity:
|
| 134 |
-
ERROR
|
| 135 |
-
|
| 136 |
-
### Procedure:
|
| 137 |
-
Boolean IfThenElseScope.EvaluateTokenCore(JsonToken,Object,Int32)
|
| 138 |
-
|
| 139 |
-
### File:
|
| 140 |
-
Src/Newtonsoft.Json.Schema/Infrastructure/Validation/IfThenElseScope.cs
|
| 141 |
-
|
| 142 |
-
### Key:
|
| 143 |
-
IfThenElseScope.cs|EvaluateTokenCore|NULL_DEREFERENCE
|
| 144 |
-
|
| 145 |
-
### Node Key:
|
| 146 |
-
85dfe737acbb6f49f447af1b2f8bcf5f
|
| 147 |
-
|
| 148 |
-
### Hash:
|
| 149 |
-
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0019/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0019/instruction.md
DELETED
|
@@ -1,156 +0,0 @@
|
|
| 1 |
-
# InferredBugs Task - Csharp
|
| 2 |
-
|
| 3 |
-
## Project Information
|
| 4 |
-
|
| 5 |
-
**Project:** Newtonsoft.Json.Schema
|
| 6 |
-
**Bug ID:** 2
|
| 7 |
-
**Language:** csharp
|
| 8 |
-
|
| 9 |
-
## Bug Information
|
| 10 |
-
|
| 11 |
-
### File-Level Changes:
|
| 12 |
-
|
| 13 |
-
**Before (Buggy File):**
|
| 14 |
-
```csharp
|
| 15 |
-
#region License
|
| 16 |
-
// Copyright (c) Newtonsoft. All Rights Reserved.
|
| 17 |
-
// License: https://raw.github.com/JamesNK/Newtonsoft.Json.Schema/master/LICENSE.md
|
| 18 |
-
#endregion
|
| 19 |
-
|
| 20 |
-
using System;
|
| 21 |
-
using System.Collections.Generic;
|
| 22 |
-
using System.Diagnostics;
|
| 23 |
-
using System.Globalization;
|
| 24 |
-
using System.Linq;
|
| 25 |
-
|
| 26 |
-
namespace Newtonsoft.Json.Schema.Infrastructure.Validation
|
| 27 |
-
{
|
| 28 |
-
internal sealed class IfThenElseScope : ConditionalScope
|
| 29 |
-
{
|
| 30 |
-
public ConditionalContext? ThenContext;
|
| 31 |
-
public ConditionalContext? ElseContext;
|
| 32 |
-
|
| 33 |
-
public JSchema? If;
|
| 34 |
-
public JSchema? Then;
|
| 35 |
-
public JSchema? Else;
|
| 36 |
-
|
| 37 |
-
public override void Initialize(ContextBase context, SchemaScope? parent, int initialDepth, ScopeType type)
|
| 38 |
-
{
|
| 39 |
-
base.Initialize(context, parent, initialDepth, type);
|
| 40 |
-
|
| 41 |
-
If = null;
|
| 42 |
-
Then = null;
|
| 43 |
-
Else = null;
|
| 44 |
-
|
| 45 |
-
ThenContext = null;
|
| 46 |
-
ElseContext = null;
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
protected override bool EvaluateTokenCore(JsonToken token, object? value, int depth)
|
| 50 |
-
{
|
| 51 |
-
SchemaScope ifScope = GetSchemaScopeBySchema(If!, token, value, depth)!;
|
| 52 |
-
|
| 53 |
-
if (ifScope.IsValid)
|
| 54 |
-
{
|
| 55 |
-
ConditionalContext.TrackEvaluatedSchema(ifScope.Schema);
|
| 56 |
-
|
| 57 |
-
if (Then != null)
|
| 58 |
-
{
|
| 59 |
-
SchemaScope thenScope = GetSchemaScopeBySchema(Then, token, value, depth)!;
|
| 60 |
-
|
| 61 |
-
if (!thenScope.IsValid)
|
| 62 |
-
{
|
| 63 |
-
RaiseError($"JSON does not match schema from 'then'.", ErrorType.Then, Then, null, thenScope.GetValidationErrors());
|
| 64 |
-
}
|
| 65 |
-
else
|
| 66 |
-
{
|
| 67 |
-
ConditionalContext.TrackEvaluatedSchema(thenScope.Schema);
|
| 68 |
-
}
|
| 69 |
-
}
|
| 70 |
-
}
|
| 71 |
-
else
|
| 72 |
-
{
|
| 73 |
-
if (Else != null)
|
| 74 |
-
{
|
| 75 |
-
SchemaScope elseScope = GetSchemaScopeBySchema(Else, token, value, depth)!;
|
| 76 |
-
|
| 77 |
-
if (!elseScope.IsValid)
|
| 78 |
-
{
|
| 79 |
-
RaiseError($"JSON does not match schema from 'else'.", ErrorType.Else, Else, null, elseScope.GetValidationErrors());
|
| 80 |
-
}
|
| 81 |
-
else
|
| 82 |
-
{
|
| 83 |
-
ConditionalContext.TrackEvaluatedSchema(elseScope.Schema);
|
| 84 |
-
}
|
| 85 |
-
}
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
return true;
|
| 89 |
-
}
|
| 90 |
-
|
| 91 |
-
public void InitializeScopes(JsonToken token, int scopeIndex)
|
| 92 |
-
{
|
| 93 |
-
InitializeScope(token, scopeIndex, If!, ConditionalContext);
|
| 94 |
-
if (Then != null)
|
| 95 |
-
{
|
| 96 |
-
InitializeScope(token, scopeIndex, Then, ThenContext!);
|
| 97 |
-
}
|
| 98 |
-
if (Else != null)
|
| 99 |
-
{
|
| 100 |
-
InitializeScope(token, scopeIndex, Else, ElseContext!);
|
| 101 |
-
}
|
| 102 |
-
}
|
| 103 |
-
|
| 104 |
-
private void InitializeScope(JsonToken token, int scopeIndex, JSchema schema, ConditionalContext context)
|
| 105 |
-
{
|
| 106 |
-
// cache this for performance
|
| 107 |
-
int scopeCurrentIndex = scopeIndex;
|
| 108 |
-
|
| 109 |
-
// check to see whether a scope with the same schema exists
|
| 110 |
-
SchemaScope? childScope = GetExistingSchemaScope(schema, ref scopeCurrentIndex);
|
| 111 |
-
|
| 112 |
-
if (childScope == null)
|
| 113 |
-
{
|
| 114 |
-
childScope = SchemaScope.CreateTokenScope(token, schema, context, null, InitialDepth);
|
| 115 |
-
}
|
| 116 |
-
|
| 117 |
-
#if DEBUG
|
| 118 |
-
childScope.ConditionalParents.Add(this);
|
| 119 |
-
#endif
|
| 120 |
-
|
| 121 |
-
ChildScopes.Add(childScope);
|
| 122 |
-
}
|
| 123 |
-
}
|
| 124 |
-
}
|
| 125 |
-
```
|
| 126 |
-
|
| 127 |
-
### Bug Type:
|
| 128 |
-
NULL_DEREFERENCE
|
| 129 |
-
|
| 130 |
-
### Qualifier:
|
| 131 |
-
pointer `ifScope` last assigned on line 37 could be null and is dereferenced at line 39, column 13.
|
| 132 |
-
|
| 133 |
-
### Severity:
|
| 134 |
-
ERROR
|
| 135 |
-
|
| 136 |
-
### Procedure:
|
| 137 |
-
Boolean IfThenElseScope.EvaluateTokenCore(JsonToken,Object,Int32)
|
| 138 |
-
|
| 139 |
-
### File:
|
| 140 |
-
Src/Newtonsoft.Json.Schema/Infrastructure/Validation/IfThenElseScope.cs
|
| 141 |
-
|
| 142 |
-
### Key:
|
| 143 |
-
IfThenElseScope.cs|EvaluateTokenCore|NULL_DEREFERENCE
|
| 144 |
-
|
| 145 |
-
### Node Key:
|
| 146 |
-
85dfe737acbb6f49f447af1b2f8bcf5f
|
| 147 |
-
|
| 148 |
-
### Hash:
|
| 149 |
-
c5adb16440390ae2fcec42a7a0956013
|
| 150 |
-
|
| 151 |
-
### Bug Type Hum:
|
| 152 |
-
Null Dereference
|
| 153 |
-
|
| 154 |
-
## Task
|
| 155 |
-
|
| 156 |
-
Fix the bug in the code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0020/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0020/instruction.md
DELETED
|
@@ -1,100 +0,0 @@
|
|
| 1 |
-
# InferredBugs Task - Csharp
|
| 2 |
-
|
| 3 |
-
## Project Information
|
| 4 |
-
|
| 5 |
-
**Project:** Dasync
|
| 6 |
-
**Bug ID:** 1
|
| 7 |
-
**Language:** csharp
|
| 8 |
-
|
| 9 |
-
## Bug Information
|
| 10 |
-
|
| 11 |
-
### File-Level Changes:
|
| 12 |
-
|
| 13 |
-
**Before (Buggy File):**
|
| 14 |
-
```csharp
|
| 15 |
-
using System;
|
| 16 |
-
using System.Reflection;
|
| 17 |
-
using System.Threading;
|
| 18 |
-
using System.Threading.Tasks;
|
| 19 |
-
|
| 20 |
-
namespace Dasync.Accessors
|
| 21 |
-
{
|
| 22 |
-
public static class DelayPromiseAccessor
|
| 23 |
-
{
|
| 24 |
-
public static bool IsDelayPromise(Task task)
|
| 25 |
-
{
|
| 26 |
-
return task.GetType().Name == "DelayPromise";
|
| 27 |
-
}
|
| 28 |
-
|
| 29 |
-
private static bool TryGetTimer(Task task, out Timer timer)
|
| 30 |
-
{
|
| 31 |
-
timer = null;
|
| 32 |
-
if (task.GetType().Name == "DelayPromise")
|
| 33 |
-
{
|
| 34 |
-
timer = task.GetType()
|
| 35 |
-
.GetField("Timer", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
|
| 36 |
-
.GetValue(task) as Timer;
|
| 37 |
-
}
|
| 38 |
-
return timer != null;
|
| 39 |
-
}
|
| 40 |
-
|
| 41 |
-
public static bool TryGetTimerStartAndDelay(Task delayPromise, out DateTime startTime, out TimeSpan delay)
|
| 42 |
-
{
|
| 43 |
-
if (TryGetTimer(delayPromise, out var timer))
|
| 44 |
-
{
|
| 45 |
-
timer.GetSettings(out var start, out var initialDelay, out var interval);
|
| 46 |
-
|
| 47 |
-
if (start.HasValue && initialDelay.HasValue)
|
| 48 |
-
{
|
| 49 |
-
startTime = start.Value;
|
| 50 |
-
delay = initialDelay.Value;
|
| 51 |
-
return true;
|
| 52 |
-
}
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
startTime = default(DateTime);
|
| 56 |
-
delay = default(TimeSpan);
|
| 57 |
-
return false;
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
public static bool TryCancelTimer(Task delayPromise)
|
| 61 |
-
{
|
| 62 |
-
if (TryGetTimer(delayPromise, out var timer))
|
| 63 |
-
{
|
| 64 |
-
timer.Dispose();
|
| 65 |
-
return true;
|
| 66 |
-
}
|
| 67 |
-
return false;
|
| 68 |
-
}
|
| 69 |
-
}
|
| 70 |
-
}
|
| 71 |
-
|
| 72 |
-
```
|
| 73 |
-
|
| 74 |
-
### Bug Type:
|
| 75 |
-
NULLPTR_DEREFERENCE
|
| 76 |
-
|
| 77 |
-
### Qualifier:
|
| 78 |
-
`timer` could be null (from the call to `DelayPromiseAccessor.TryGetTimer(...)` on line 48) and is dereferenced.
|
| 79 |
-
|
| 80 |
-
### Severity:
|
| 81 |
-
ERROR
|
| 82 |
-
|
| 83 |
-
### Procedure:
|
| 84 |
-
Boolean DelayPromiseAccessor.TryCancelTimer(Task)
|
| 85 |
-
|
| 86 |
-
### File:
|
| 87 |
-
Engine/Accessors/DelayPromiseAccessor.cs
|
| 88 |
-
|
| 89 |
-
### Key:
|
| 90 |
-
DelayPromiseAccessor.cs|TryCancelTimer|NULLPTR_DEREFERENCE
|
| 91 |
-
|
| 92 |
-
### Hash:
|
| 93 |
-
ffc070435244d564e337feb3c61d4e58
|
| 94 |
-
|
| 95 |
-
### Bug Type Hum:
|
| 96 |
-
Null Dereference
|
| 97 |
-
|
| 98 |
-
## Task
|
| 99 |
-
|
| 100 |
-
Fix the bug in the code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0021/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0021/instruction.md
DELETED
|
@@ -1,110 +0,0 @@
|
|
| 1 |
-
# InferredBugs Task - Csharp
|
| 2 |
-
|
| 3 |
-
## Project Information
|
| 4 |
-
|
| 5 |
-
**Project:** durabletask
|
| 6 |
-
**Bug ID:** 1
|
| 7 |
-
**Language:** csharp
|
| 8 |
-
|
| 9 |
-
## Bug Information
|
| 10 |
-
|
| 11 |
-
### File-Level Changes:
|
| 12 |
-
|
| 13 |
-
**Before (Buggy File):**
|
| 14 |
-
```csharp
|
| 15 |
-
// ----------------------------------------------------------------------------------
|
| 16 |
-
// Copyright Microsoft Corporation
|
| 17 |
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 18 |
-
// you may not use this file except in compliance with the License.
|
| 19 |
-
// You may obtain a copy of the License at
|
| 20 |
-
// http://www.apache.org/licenses/LICENSE-2.0
|
| 21 |
-
// Unless required by applicable law or agreed to in writing, software
|
| 22 |
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 23 |
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 24 |
-
// See the License for the specific language governing permissions and
|
| 25 |
-
// limitations under the License.
|
| 26 |
-
// ----------------------------------------------------------------------------------
|
| 27 |
-
|
| 28 |
-
namespace DurableTask.AzureServiceFabric.Service
|
| 29 |
-
{
|
| 30 |
-
using System;
|
| 31 |
-
using System.Net;
|
| 32 |
-
using System.Web.Http;
|
| 33 |
-
using System.Web.Http.ExceptionHandling;
|
| 34 |
-
|
| 35 |
-
using DurableTask.Core;
|
| 36 |
-
using DurableTask.AzureServiceFabric;
|
| 37 |
-
using Microsoft.Extensions.DependencyInjection;
|
| 38 |
-
using Owin;
|
| 39 |
-
|
| 40 |
-
class Startup : IOwinAppBuilder
|
| 41 |
-
{
|
| 42 |
-
FabricOrchestrationProvider fabricOrchestrationProvider;
|
| 43 |
-
string listeningAddress;
|
| 44 |
-
|
| 45 |
-
public Startup(string listeningAddress, FabricOrchestrationProvider fabricOrchestrationProvider)
|
| 46 |
-
{
|
| 47 |
-
this.listeningAddress = listeningAddress ?? throw new ArgumentNullException(nameof(listeningAddress));
|
| 48 |
-
this.fabricOrchestrationProvider = fabricOrchestrationProvider ?? throw new ArgumentNullException(nameof(fabricOrchestrationProvider));
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
-
public string GetListeningAddress()
|
| 52 |
-
{
|
| 53 |
-
return this.listeningAddress;
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
private ServiceProvider GenerateServiceProvider()
|
| 57 |
-
{
|
| 58 |
-
var services = new ServiceCollection();
|
| 59 |
-
services.AddSingleton<IOrchestrationServiceClient>(this.fabricOrchestrationProvider.OrchestrationServiceClient);
|
| 60 |
-
services.AddTransient<FabricOrchestrationServiceController>();
|
| 61 |
-
services.AddSingleton<IExceptionLogger, ProxyServiceExceptionLogger>();
|
| 62 |
-
services.AddSingleton<IExceptionHandler, ProxyServiceExceptionHandler>();
|
| 63 |
-
var serviceProvider = services.BuildServiceProvider();
|
| 64 |
-
return serviceProvider;
|
| 65 |
-
}
|
| 66 |
-
|
| 67 |
-
void IOwinAppBuilder.Startup(IAppBuilder appBuilder)
|
| 68 |
-
{
|
| 69 |
-
ServicePointManager.DefaultConnectionLimit = 256;
|
| 70 |
-
HttpConfiguration config = new HttpConfiguration();
|
| 71 |
-
config.MapHttpAttributeRoutes();
|
| 72 |
-
config.DependencyResolver = new DefaultDependencyResolver(GenerateServiceProvider());
|
| 73 |
-
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
|
| 74 |
-
config.Formatters.Remove(config.Formatters.XmlFormatter);
|
| 75 |
-
config.Formatters.Remove(config.Formatters.FormUrlEncodedFormatter);
|
| 76 |
-
config.Formatters.JsonFormatter.SerializerSettings.TypeNameHandling = Newtonsoft.Json.TypeNameHandling.All;
|
| 77 |
-
appBuilder.UseWebApi(config);
|
| 78 |
-
}
|
| 79 |
-
}
|
| 80 |
-
}
|
| 81 |
-
|
| 82 |
-
```
|
| 83 |
-
|
| 84 |
-
### Bug Type:
|
| 85 |
-
DOTNET_RESOURCE_LEAK
|
| 86 |
-
|
| 87 |
-
### Qualifier:
|
| 88 |
-
Leaked resource config of type System.Web.Http.HttpConfiguration, Leaked resource (output of DurableTask.AzureServiceFabric.Service.DefaultDependencyResolver::.ctor() at Line 58) of type DurableTask.AzureServiceFabric.Service.DefaultDependencyResolver in method "Void Startup.DurableTask.AzureServiceFabric.Service.IOwinAppBuilder.Startup(IAppBuilder)".
|
| 89 |
-
|
| 90 |
-
### Severity:
|
| 91 |
-
ERROR
|
| 92 |
-
|
| 93 |
-
### Procedure:
|
| 94 |
-
Void Startup.DurableTask.AzureServiceFabric.Service.IOwinAppBuilder.Startup(IAppBuilder)
|
| 95 |
-
|
| 96 |
-
### File:
|
| 97 |
-
src/DurableTask.AzureServiceFabric/Service/Startup.cs
|
| 98 |
-
|
| 99 |
-
### Key:
|
| 100 |
-
Startup.cs|DurableTask.AzureServiceFabric.Service.IOwinAppBuilder.Startup|DOTNET_RESOURCE_LEAK
|
| 101 |
-
|
| 102 |
-
### Hash:
|
| 103 |
-
7fc7b185fd16e66488edf413718ddc59
|
| 104 |
-
|
| 105 |
-
### Bug Type Hum:
|
| 106 |
-
Dotnet Resource Leak
|
| 107 |
-
|
| 108 |
-
## Task
|
| 109 |
-
|
| 110 |
-
Fix the bug in the code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0022/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0022/instruction.md
DELETED
|
@@ -1,229 +0,0 @@
|
|
| 1 |
-
# InferredBugs Task - Csharp
|
| 2 |
-
|
| 3 |
-
## Project Information
|
| 4 |
-
|
| 5 |
-
**Project:** AMBROSIA
|
| 6 |
-
**Bug ID:** 1
|
| 7 |
-
**Language:** csharp
|
| 8 |
-
|
| 9 |
-
## Bug Information
|
| 10 |
-
|
| 11 |
-
### File-Level Changes:
|
| 12 |
-
|
| 13 |
-
**Before (Buggy File):**
|
| 14 |
-
```csharp
|
| 15 |
-
using System;
|
| 16 |
-
using System.Net;
|
| 17 |
-
using System.Net.Sockets;
|
| 18 |
-
using System.Configuration;
|
| 19 |
-
using System.Diagnostics;
|
| 20 |
-
using System.IO;
|
| 21 |
-
using CRA.ClientLibrary;
|
| 22 |
-
using System.Reflection;
|
| 23 |
-
using Ambrosia;
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
namespace CRA.Worker
|
| 27 |
-
{
|
| 28 |
-
public class Program
|
| 29 |
-
{
|
| 30 |
-
private static string _instanceName;
|
| 31 |
-
private static int _port = -1;
|
| 32 |
-
private static string _ipAddress;
|
| 33 |
-
private static string _secureNetworkAssemblyName;
|
| 34 |
-
private static string _secureNetworkClassName;
|
| 35 |
-
private static bool _isActiveActive = false;
|
| 36 |
-
private static int _replicaNumber = 0;
|
| 37 |
-
|
| 38 |
-
public static void main(string[] args)
|
| 39 |
-
{
|
| 40 |
-
ParseAndValidateOptions(args);
|
| 41 |
-
|
| 42 |
-
var replicaName = $"{_instanceName}{_replicaNumber}";
|
| 43 |
-
|
| 44 |
-
if (_ipAddress == null)
|
| 45 |
-
{
|
| 46 |
-
_ipAddress = GetLocalIPAddress();
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
string storageConnectionString = null;
|
| 50 |
-
|
| 51 |
-
if (storageConnectionString == null)
|
| 52 |
-
{
|
| 53 |
-
storageConnectionString = Environment.GetEnvironmentVariable("AZURE_STORAGE_CONN_STRING");
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
if (!_isActiveActive && _replicaNumber != 0)
|
| 57 |
-
{
|
| 58 |
-
throw new InvalidOperationException("Can't specify a replica number without the activeActive flag");
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
-
if (storageConnectionString == null)
|
| 62 |
-
{
|
| 63 |
-
throw new InvalidOperationException("Azure storage connection string not found. Use appSettings in your app.config to provide this using the key AZURE_STORAGE_CONN_STRING, or use the environment variable AZURE_STORAGE_CONN_STRING.");
|
| 64 |
-
}
|
| 65 |
-
|
| 66 |
-
int connectionsPoolPerWorker;
|
| 67 |
-
string connectionsPoolPerWorkerString = "0";
|
| 68 |
-
if (connectionsPoolPerWorkerString != null)
|
| 69 |
-
{
|
| 70 |
-
try
|
| 71 |
-
{
|
| 72 |
-
connectionsPoolPerWorker = Convert.ToInt32(connectionsPoolPerWorkerString);
|
| 73 |
-
}
|
| 74 |
-
catch
|
| 75 |
-
{
|
| 76 |
-
throw new InvalidOperationException("Maximum number of connections per CRA worker is wrong. Use appSettings in your app.config to provide this using the key CRA_WORKER_MAX_CONN_POOL.");
|
| 77 |
-
}
|
| 78 |
-
}
|
| 79 |
-
else
|
| 80 |
-
{
|
| 81 |
-
connectionsPoolPerWorker = 1000;
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
ISecureStreamConnectionDescriptor descriptor = null;
|
| 85 |
-
if (_secureNetworkClassName != null)
|
| 86 |
-
{
|
| 87 |
-
Type type;
|
| 88 |
-
if (_secureNetworkAssemblyName != null)
|
| 89 |
-
{
|
| 90 |
-
var assembly = Assembly.Load(_secureNetworkAssemblyName);
|
| 91 |
-
type = assembly.GetType(_secureNetworkClassName);
|
| 92 |
-
}
|
| 93 |
-
else
|
| 94 |
-
{
|
| 95 |
-
type = Type.GetType(_secureNetworkClassName);
|
| 96 |
-
}
|
| 97 |
-
descriptor = (ISecureStreamConnectionDescriptor)Activator.CreateInstance(type);
|
| 98 |
-
}
|
| 99 |
-
|
| 100 |
-
var dataProvider = new CRA.DataProvider.Azure.AzureDataProvider(storageConnectionString);
|
| 101 |
-
var worker = new CRAWorker
|
| 102 |
-
(replicaName, _ipAddress, _port,
|
| 103 |
-
dataProvider, descriptor, connectionsPoolPerWorker);
|
| 104 |
-
|
| 105 |
-
worker.DisableDynamicLoading();
|
| 106 |
-
worker.SideloadVertex(new AmbrosiaRuntime(), "ambrosia");
|
| 107 |
-
|
| 108 |
-
worker.Start();
|
| 109 |
-
}
|
| 110 |
-
|
| 111 |
-
static void Main(string[] args)
|
| 112 |
-
{
|
| 113 |
-
GenericLogsInterface.SetToGenericLogs();
|
| 114 |
-
//AzureBlobsLogsInterface.SetToAzureBlobsLogs();
|
| 115 |
-
main(args);
|
| 116 |
-
}
|
| 117 |
-
|
| 118 |
-
private static string GetLocalIPAddress()
|
| 119 |
-
{
|
| 120 |
-
var host = Dns.GetHostEntry(Dns.GetHostName());
|
| 121 |
-
foreach (var ip in host.AddressList)
|
| 122 |
-
{
|
| 123 |
-
if (ip.AddressFamily == AddressFamily.InterNetwork)
|
| 124 |
-
{
|
| 125 |
-
return ip.ToString();
|
| 126 |
-
}
|
| 127 |
-
}
|
| 128 |
-
throw new InvalidOperationException("Local IP Address Not Found!");
|
| 129 |
-
}
|
| 130 |
-
|
| 131 |
-
private static void ParseAndValidateOptions(string[] args)
|
| 132 |
-
{
|
| 133 |
-
var options = ParseOptions(args, out var shouldShowHelp);
|
| 134 |
-
ValidateOptions(options, shouldShowHelp);
|
| 135 |
-
}
|
| 136 |
-
|
| 137 |
-
private static OptionSet ParseOptions(string[] args, out bool shouldShowHelp)
|
| 138 |
-
{
|
| 139 |
-
var showHelp = false;
|
| 140 |
-
var options = new OptionSet {
|
| 141 |
-
{ "i|instanceName=", "The instance name [REQUIRED].", n => _instanceName = n },
|
| 142 |
-
{ "p|port=", "An port number [REQUIRED].", p => _port = Int32.Parse(p) },
|
| 143 |
-
{"aa|activeActive", "Is active-active enabled.", aa => _isActiveActive = true},
|
| 144 |
-
{ "r|replicaNum=", "The replica #", r => { _replicaNumber = int.Parse(r); _isActiveActive=true; } },
|
| 145 |
-
{ "an|assemblyName=", "The secure network assembly name.", an => _secureNetworkAssemblyName = an },
|
| 146 |
-
{ "ac|assemblyClass=", "The secure network assembly class.", ac => _secureNetworkClassName = ac },
|
| 147 |
-
{ "ip|IPAddr=", "Override automatic self IP detection", i => _ipAddress = i },
|
| 148 |
-
{ "h|help", "show this message and exit", h => showHelp = h != null },
|
| 149 |
-
{ "rp|receivePort=", "The service receive from port override.", rp => StartupParamOverrides.receivePort = int.Parse(rp) },
|
| 150 |
-
{ "sp|sendPort=", "The service send to port override.", sp => StartupParamOverrides.sendPort = int.Parse(sp) },
|
| 151 |
-
};
|
| 152 |
-
|
| 153 |
-
try
|
| 154 |
-
{
|
| 155 |
-
options.Parse(args);
|
| 156 |
-
}
|
| 157 |
-
catch (OptionException e)
|
| 158 |
-
{
|
| 159 |
-
Console.WriteLine("Invalid arguments: " + e.Message);
|
| 160 |
-
ShowHelp(options);
|
| 161 |
-
Environment.Exit(1);
|
| 162 |
-
}
|
| 163 |
-
|
| 164 |
-
shouldShowHelp = showHelp;
|
| 165 |
-
|
| 166 |
-
return options;
|
| 167 |
-
}
|
| 168 |
-
|
| 169 |
-
private static void ValidateOptions(OptionSet options, bool shouldShowHelp)
|
| 170 |
-
{
|
| 171 |
-
var errorMessage = string.Empty;
|
| 172 |
-
if (_instanceName == null) errorMessage += "Instance name is required.";
|
| 173 |
-
if (_port == -1) errorMessage += "Port number is required.";
|
| 174 |
-
|
| 175 |
-
if (errorMessage != string.Empty)
|
| 176 |
-
{
|
| 177 |
-
Console.WriteLine(errorMessage);
|
| 178 |
-
ShowHelp(options);
|
| 179 |
-
Environment.Exit(1);
|
| 180 |
-
}
|
| 181 |
-
|
| 182 |
-
if (shouldShowHelp) ShowHelp(options);
|
| 183 |
-
}
|
| 184 |
-
|
| 185 |
-
private static void ShowHelp(OptionSet options)
|
| 186 |
-
{
|
| 187 |
-
var name = typeof(Program).Assembly.GetName().Name;
|
| 188 |
-
Console.WriteLine("Worker for Common Runtime for Applications (CRA) [http://github.com/Microsoft/CRA]");
|
| 189 |
-
#if NETCORE
|
| 190 |
-
Console.WriteLine($"Usage: dotnet {name}.dll [OPTIONS]\nOptions:");
|
| 191 |
-
#else
|
| 192 |
-
Console.WriteLine($"Usage: {name}.exe [OPTIONS]\nOptions:");
|
| 193 |
-
#endif
|
| 194 |
-
|
| 195 |
-
options.WriteOptionDescriptions(Console.Out);
|
| 196 |
-
Environment.Exit(0);
|
| 197 |
-
}
|
| 198 |
-
}
|
| 199 |
-
}
|
| 200 |
-
|
| 201 |
-
```
|
| 202 |
-
|
| 203 |
-
### Bug Type:
|
| 204 |
-
DOTNET_RESOURCE_LEAK
|
| 205 |
-
|
| 206 |
-
### Qualifier:
|
| 207 |
-
Leaked resource worker of type CRA.ClientLibrary.CRAWorker, Leaked resource (output of Ambrosia.AmbrosiaRuntime::.ctor() at Line 92) of type CRA.ClientLibrary.VertexBase, Leaked resource (output of Ambrosia.AmbrosiaRuntime::.ctor() at Line 92) of type CRA.ClientLibrary.VertexBase in method "Void Program.main(String[])".
|
| 208 |
-
|
| 209 |
-
### Severity:
|
| 210 |
-
ERROR
|
| 211 |
-
|
| 212 |
-
### Procedure:
|
| 213 |
-
Void Program.main(String[])
|
| 214 |
-
|
| 215 |
-
### File:
|
| 216 |
-
ImmortalCoordinator/Program.cs
|
| 217 |
-
|
| 218 |
-
### Key:
|
| 219 |
-
Program.cs|main|DOTNET_RESOURCE_LEAK
|
| 220 |
-
|
| 221 |
-
### Hash:
|
| 222 |
-
9de94f4d7e30f56a2e5ed6b6f41160a2
|
| 223 |
-
|
| 224 |
-
### Bug Type Hum:
|
| 225 |
-
Dotnet Resource Leak
|
| 226 |
-
|
| 227 |
-
## Task
|
| 228 |
-
|
| 229 |
-
Fix the bug in the code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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f /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0023/instruction.md
DELETED
|
@@ -1,255 +0,0 @@
|
|
| 1 |
-
# InferredBugs Task - Csharp
|
| 2 |
-
|
| 3 |
-
## Project Information
|
| 4 |
-
|
| 5 |
-
**Project:** UABEA
|
| 6 |
-
**Bug ID:** 1
|
| 7 |
-
**Language:** csharp
|
| 8 |
-
|
| 9 |
-
## Bug Information
|
| 10 |
-
|
| 11 |
-
### File-Level Changes:
|
| 12 |
-
|
| 13 |
-
**Before (Buggy File):**
|
| 14 |
-
```csharp
|
| 15 |
-
using AssetsTools.NET;
|
| 16 |
-
using AssetsTools.NET.Extra;
|
| 17 |
-
using Avalonia;
|
| 18 |
-
using Avalonia.Collections;
|
| 19 |
-
using Avalonia.Controls;
|
| 20 |
-
using System;
|
| 21 |
-
using System.Collections.Generic;
|
| 22 |
-
using System.Linq;
|
| 23 |
-
using System.Text;
|
| 24 |
-
using System.Threading.Tasks;
|
| 25 |
-
|
| 26 |
-
namespace UABEAvalonia
|
| 27 |
-
{
|
| 28 |
-
public class AssetDataTreeView : TreeView
|
| 29 |
-
{
|
| 30 |
-
private AssetWorkspace workspace;
|
| 31 |
-
|
| 32 |
-
private AvaloniaList<TreeViewItem> ListItems => (AvaloniaList<TreeViewItem>)Items;
|
| 33 |
-
|
| 34 |
-
public void Init(AssetWorkspace workspace)
|
| 35 |
-
{
|
| 36 |
-
this.workspace = workspace;
|
| 37 |
-
Reset();
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
-
public void Reset()
|
| 41 |
-
{
|
| 42 |
-
Items = new AvaloniaList<TreeViewItem>();
|
| 43 |
-
}
|
| 44 |
-
|
| 45 |
-
public void LoadComponent(AssetContainer container)
|
| 46 |
-
{
|
| 47 |
-
if (workspace == null)
|
| 48 |
-
return;
|
| 49 |
-
|
| 50 |
-
AssetTypeValueField baseField = workspace.GetBaseField(container);
|
| 51 |
-
TreeViewItem baseItem = CreateTreeItem($"{baseField.GetFieldType()} {baseField.GetName()}");
|
| 52 |
-
|
| 53 |
-
TreeViewItem arrayIndexTreeItem = CreateTreeItem("Loading...");
|
| 54 |
-
baseItem.Items = new AvaloniaList<TreeViewItem>() { arrayIndexTreeItem };
|
| 55 |
-
ListItems.Add(baseItem);
|
| 56 |
-
|
| 57 |
-
SetTreeItemEvents(baseItem, container.FileInstance, container.PathId, baseField);
|
| 58 |
-
baseItem.IsExpanded = true;
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
-
private TreeViewItem CreateTreeItem(string text)
|
| 62 |
-
{
|
| 63 |
-
return new TreeViewItem() { Header = text };
|
| 64 |
-
}
|
| 65 |
-
|
| 66 |
-
//lazy load tree items. avalonia is really slow to load if
|
| 67 |
-
//we just throw everything in the treeview at once
|
| 68 |
-
private void SetTreeItemEvents(TreeViewItem item, AssetsFileInstance fromFile, long fromPathId, AssetTypeValueField field)
|
| 69 |
-
{
|
| 70 |
-
item.Tag = new AssetDataTreeViewItem(fromFile, fromPathId);
|
| 71 |
-
//avalonia's treeviews have no Expanded event so this is all we can do
|
| 72 |
-
var expandObs = item.GetObservable(TreeViewItem.IsExpandedProperty);
|
| 73 |
-
expandObs.Subscribe(isExpanded =>
|
| 74 |
-
{
|
| 75 |
-
AssetDataTreeViewItem itemInfo = (AssetDataTreeViewItem)item.Tag;
|
| 76 |
-
if (isExpanded && !itemInfo.loaded)
|
| 77 |
-
{
|
| 78 |
-
itemInfo.loaded = true; //don't load this again
|
| 79 |
-
TreeLoad(fromFile, field, fromPathId, item);
|
| 80 |
-
}
|
| 81 |
-
});
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
private void SetPPtrEvents(TreeViewItem item, AssetsFileInstance fromFile, long fromPathId, AssetContainer cont)
|
| 85 |
-
{
|
| 86 |
-
item.Tag = new AssetDataTreeViewItem(fromFile, fromPathId);
|
| 87 |
-
var expandObs = item.GetObservable(TreeViewItem.IsExpandedProperty);
|
| 88 |
-
expandObs.Subscribe(isExpanded =>
|
| 89 |
-
{
|
| 90 |
-
AssetDataTreeViewItem itemInfo = (AssetDataTreeViewItem)item.Tag;
|
| 91 |
-
if (isExpanded && !itemInfo.loaded)
|
| 92 |
-
{
|
| 93 |
-
itemInfo.loaded = true; //don't load this again
|
| 94 |
-
|
| 95 |
-
if (cont != null)
|
| 96 |
-
{
|
| 97 |
-
AssetTypeValueField baseField = workspace.GetBaseField(cont);
|
| 98 |
-
TreeViewItem baseItem = CreateTreeItem($"{baseField.GetFieldType()} {baseField.GetName()}");
|
| 99 |
-
|
| 100 |
-
TreeViewItem arrayIndexTreeItem = CreateTreeItem("Loading...");
|
| 101 |
-
baseItem.Items = new List<TreeViewItem>() { arrayIndexTreeItem };
|
| 102 |
-
item.Items = new List<TreeViewItem>() { baseItem };
|
| 103 |
-
SetTreeItemEvents(baseItem, cont.FileInstance, fromPathId, baseField);
|
| 104 |
-
}
|
| 105 |
-
else
|
| 106 |
-
{
|
| 107 |
-
item.Items = new List<TreeViewItem>() { CreateTreeItem("[null asset]") };
|
| 108 |
-
}
|
| 109 |
-
}
|
| 110 |
-
});
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
private void TreeLoad(AssetsFileInstance fromFile, AssetTypeValueField assetField, long fromPathId, TreeViewItem treeItem)
|
| 114 |
-
{
|
| 115 |
-
if (assetField.childrenCount == 0) return;
|
| 116 |
-
|
| 117 |
-
int arrayIdx = 0;
|
| 118 |
-
List<TreeViewItem> items = new List<TreeViewItem>(assetField.childrenCount + 1);
|
| 119 |
-
|
| 120 |
-
AssetTypeTemplateField assetFieldTemplate = assetField.GetTemplateField();
|
| 121 |
-
bool isArray = assetFieldTemplate.isArray;
|
| 122 |
-
|
| 123 |
-
if (isArray)
|
| 124 |
-
{
|
| 125 |
-
int size = assetField.GetValue().AsArray().size;
|
| 126 |
-
AssetTypeTemplateField sizeTemplate = assetFieldTemplate.children[0];
|
| 127 |
-
TreeViewItem arrayIndexTreeItem = CreateTreeItem($"{sizeTemplate.type} {sizeTemplate.name} = {size}");
|
| 128 |
-
items.Add(arrayIndexTreeItem);
|
| 129 |
-
}
|
| 130 |
-
|
| 131 |
-
foreach (AssetTypeValueField childField in assetField.children)
|
| 132 |
-
{
|
| 133 |
-
if (childField == null) return;
|
| 134 |
-
string value = "";
|
| 135 |
-
if (childField.GetValue() != null)
|
| 136 |
-
{
|
| 137 |
-
EnumValueTypes evt = childField.GetValue().GetValueType();
|
| 138 |
-
string quote = "";
|
| 139 |
-
if (evt == EnumValueTypes.String) quote = "\"";
|
| 140 |
-
if (1 <= (int)evt && (int)evt <= 12)
|
| 141 |
-
{
|
| 142 |
-
value = $" = {quote}{childField.GetValue().AsString()}{quote}";
|
| 143 |
-
}
|
| 144 |
-
if (evt == EnumValueTypes.Array ||
|
| 145 |
-
evt == EnumValueTypes.ByteArray)
|
| 146 |
-
{
|
| 147 |
-
value = $" (size {childField.childrenCount})";
|
| 148 |
-
}
|
| 149 |
-
}
|
| 150 |
-
|
| 151 |
-
if (isArray)
|
| 152 |
-
{
|
| 153 |
-
TreeViewItem arrayIndexTreeItem = CreateTreeItem($"{arrayIdx}");
|
| 154 |
-
items.Add(arrayIndexTreeItem);
|
| 155 |
-
|
| 156 |
-
TreeViewItem childTreeItem = CreateTreeItem($"{childField.GetFieldType()} {childField.GetName()}{value}");
|
| 157 |
-
arrayIndexTreeItem.Items = new List<TreeViewItem>() { childTreeItem };
|
| 158 |
-
|
| 159 |
-
if (childField.childrenCount > 0)
|
| 160 |
-
{
|
| 161 |
-
TreeViewItem dummyItem = CreateTreeItem("Loading...");
|
| 162 |
-
childTreeItem.Items = new List<TreeViewItem>() { dummyItem };
|
| 163 |
-
SetTreeItemEvents(childTreeItem, fromFile, fromPathId, childField);
|
| 164 |
-
}
|
| 165 |
-
|
| 166 |
-
arrayIdx++;
|
| 167 |
-
}
|
| 168 |
-
else
|
| 169 |
-
{
|
| 170 |
-
TreeViewItem childTreeItem = CreateTreeItem($"{childField.GetFieldType()} {childField.GetName()}{value}");
|
| 171 |
-
items.Add(childTreeItem);
|
| 172 |
-
|
| 173 |
-
if (childField.childrenCount > 0)
|
| 174 |
-
{
|
| 175 |
-
TreeViewItem dummyItem = CreateTreeItem("Loading...");
|
| 176 |
-
childTreeItem.Items = new List<TreeViewItem>() { dummyItem };
|
| 177 |
-
SetTreeItemEvents(childTreeItem, fromFile, fromPathId, childField);
|
| 178 |
-
}
|
| 179 |
-
}
|
| 180 |
-
}
|
| 181 |
-
|
| 182 |
-
string templateFieldType = assetField.templateField.type;
|
| 183 |
-
if (templateFieldType.StartsWith("PPtr<") && templateFieldType.EndsWith(">"))
|
| 184 |
-
{
|
| 185 |
-
var fileIdField = assetField.Get("m_FileID");
|
| 186 |
-
var pathIdField = assetField.Get("m_PathID");
|
| 187 |
-
bool pptrValid = !fileIdField.IsDummy() && !pathIdField.IsDummy();
|
| 188 |
-
|
| 189 |
-
if (pptrValid)
|
| 190 |
-
{
|
| 191 |
-
int fileId = fileIdField.GetValue().AsInt();
|
| 192 |
-
long pathId = pathIdField.GetValue().AsInt64();
|
| 193 |
-
|
| 194 |
-
AssetContainer cont = workspace.GetAssetContainer(fromFile, fileId, pathId, false);
|
| 195 |
-
|
| 196 |
-
TreeViewItem childTreeItem = CreateTreeItem($"[view asset]");
|
| 197 |
-
items.Add(childTreeItem);
|
| 198 |
-
|
| 199 |
-
TreeViewItem dummyItem = CreateTreeItem("Loading...");
|
| 200 |
-
childTreeItem.Items = new List<TreeViewItem>() { dummyItem };
|
| 201 |
-
SetPPtrEvents(childTreeItem, fromFile, pathId, cont);
|
| 202 |
-
}
|
| 203 |
-
}
|
| 204 |
-
|
| 205 |
-
treeItem.Items = items;
|
| 206 |
-
}
|
| 207 |
-
}
|
| 208 |
-
|
| 209 |
-
public class AssetDataTreeViewItem
|
| 210 |
-
{
|
| 211 |
-
public bool loaded;
|
| 212 |
-
public AssetsFileInstance fromFile;
|
| 213 |
-
public long fromPathId;
|
| 214 |
-
|
| 215 |
-
public AssetDataTreeViewItem(AssetsFileInstance fromFile, long fromPathId)
|
| 216 |
-
{
|
| 217 |
-
this.loaded = false;
|
| 218 |
-
this.fromFile = fromFile;
|
| 219 |
-
this.fromPathId = fromPathId;
|
| 220 |
-
}
|
| 221 |
-
}
|
| 222 |
-
}
|
| 223 |
-
|
| 224 |
-
```
|
| 225 |
-
|
| 226 |
-
### Bug Type:
|
| 227 |
-
NULL_DEREFERENCE
|
| 228 |
-
|
| 229 |
-
### Qualifier:
|
| 230 |
-
pointer `baseField` last assigned on line 36 could be null and is dereferenced at line 38, column 13.
|
| 231 |
-
|
| 232 |
-
### Severity:
|
| 233 |
-
ERROR
|
| 234 |
-
|
| 235 |
-
### Procedure:
|
| 236 |
-
Void AssetDataTreeView.LoadComponent(AssetContainer)
|
| 237 |
-
|
| 238 |
-
### File:
|
| 239 |
-
UABEAvalonia/AssetDataTreeView.cs
|
| 240 |
-
|
| 241 |
-
### Key:
|
| 242 |
-
AssetDataTreeView.cs|LoadComponent|NULL_DEREFERENCE
|
| 243 |
-
|
| 244 |
-
### Node Key:
|
| 245 |
-
0a2f2289efc1b4f27401d167fdf3ab36
|
| 246 |
-
|
| 247 |
-
### Hash:
|
| 248 |
-
ae3ba6ba176748ccddff32104e180bcf
|
| 249 |
-
|
| 250 |
-
### Bug Type Hum:
|
| 251 |
-
Null Dereference
|
| 252 |
-
|
| 253 |
-
## Task
|
| 254 |
-
|
| 255 |
-
Fix the bug in the code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0024/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inferredbugs-0024/instruction.md
DELETED
|
@@ -1,59 +0,0 @@
|
|
| 1 |
-
# InferredBugs Task - Csharp
|
| 2 |
-
|
| 3 |
-
## Project Information
|
| 4 |
-
|
| 5 |
-
**Project:** luban
|
| 6 |
-
**Bug ID:** 1
|
| 7 |
-
**Language:** csharp
|
| 8 |
-
|
| 9 |
-
## Bug Information
|
| 10 |
-
|
| 11 |
-
### File-Level Changes:
|
| 12 |
-
|
| 13 |
-
**Before (Buggy File):**
|
| 14 |
-
```csharp
|
| 15 |
-
namespace Luban.Common.Utils
|
| 16 |
-
{
|
| 17 |
-
public static class LogUtil
|
| 18 |
-
{
|
| 19 |
-
public static void InitSimpleNLogConfigure(NLog.LogLevel minConsoleLogLevel)
|
| 20 |
-
{
|
| 21 |
-
var logConfig = new NLog.Config.LoggingConfiguration();
|
| 22 |
-
//var layout = NLog.Layouts.Layout.FromString("${longdate}|${level:uppercase=true}|${threadid}|${message}${onexception:${newline}${exception:format=tostring}${exception:format=StackTrace}}");
|
| 23 |
-
var layout = NLog.Layouts.Layout.FromString("${longdate}|${message}${onexception:${newline}${exception:format=tostring}${exception:format=StackTrace}}");
|
| 24 |
-
logConfig.AddTarget("console", new NLog.Targets.ColoredConsoleTarget() { Layout = layout });
|
| 25 |
-
logConfig.AddRule(minConsoleLogLevel, NLog.LogLevel.Fatal, "console");
|
| 26 |
-
NLog.LogManager.Configuration = logConfig;
|
| 27 |
-
}
|
| 28 |
-
}
|
| 29 |
-
}
|
| 30 |
-
|
| 31 |
-
```
|
| 32 |
-
|
| 33 |
-
### Bug Type:
|
| 34 |
-
DOTNET_RESOURCE_LEAK
|
| 35 |
-
|
| 36 |
-
### Qualifier:
|
| 37 |
-
Leaked resource (output of NLog.Targets.ColoredConsoleTarget::.ctor() at Line 10) of type NLog.Targets.ColoredConsoleTarget in method "Void LogUtil.InitSimpleNLogConfigure(LogLevel)".
|
| 38 |
-
|
| 39 |
-
### Severity:
|
| 40 |
-
ERROR
|
| 41 |
-
|
| 42 |
-
### Procedure:
|
| 43 |
-
Void LogUtil.InitSimpleNLogConfigure(LogLevel)
|
| 44 |
-
|
| 45 |
-
### File:
|
| 46 |
-
src/Luban.Common/Source/Utils/LogUtil.cs
|
| 47 |
-
|
| 48 |
-
### Key:
|
| 49 |
-
LogUtil.cs|InitSimpleNLogConfigure|DOTNET_RESOURCE_LEAK
|
| 50 |
-
|
| 51 |
-
### Hash:
|
| 52 |
-
33fce8b9796d5ea4930c2b3942928fd5
|
| 53 |
-
|
| 54 |
-
### Bug Type Hum:
|
| 55 |
-
Dotnet Resource Leak
|
| 56 |
-
|
| 57 |
-
## Task
|
| 58 |
-
|
| 59 |
-
Fix the bug in the code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|