Skip to content

Commit

Permalink
fix: crash when guid can't be parsed (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbyg603 authored Sep 21, 2023
1 parent 44b5b98 commit b93aa61
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
10 changes: 4 additions & 6 deletions bin/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /usr/bin/env node
import { ApiClient, BugSplatApiClient, OAuthClientCredentialsClient, SymbolFile, UploadableFile, VersionsApiClient } from '@bugsplat/js-api-client';
import { ApiClient, BugSplatApiClient, OAuthClientCredentialsClient, SymbolFile, VersionsApiClient } from '@bugsplat/js-api-client';
import commandLineArgs, { CommandLineOptions } from 'command-line-args';
import commandLineUsage from 'command-line-usage';
import firstline from 'firstline';
Expand All @@ -8,9 +8,9 @@ import { mkdir, readFile, rm, stat } from 'fs/promises';
import glob from 'glob-promise';
import { basename, dirname, extname, join, relative } from 'path';
import { CommandLineDefinition, argDefinitions, maxParallelThreads, usageDefinitions } from './command-line-definitions';
import { tryGetPdbGuid, tryGetPeGuid } from './pdb';
import { createWorkersFromSymbolFiles } from './worker';
import { Zip } from './zip';
import { PdbFile, PeFile } from 'pdb-guid';

const currentDirectory = process ? process.cwd() : __dirname;
const tmpDir = join(currentDirectory, 'tmp');
Expand Down Expand Up @@ -152,13 +152,11 @@ async function createSymbolFile(directory: string, symbolFilePath: string): Prom
let dbgId = '';

if (isPdbFile) {
const pdbFile = await PdbFile.createFromFile(symbolFilePath);
dbgId = `${pdbFile.guid}`;
dbgId = await tryGetPdbGuid(symbolFilePath);
}

if (isPeFile) {
const peFile = await PeFile.createFromFile(symbolFilePath);
dbgId = `${peFile.guid}`;
dbgId = await tryGetPeGuid(symbolFilePath);
}

if (isSymFile) {
Expand Down
23 changes: 23 additions & 0 deletions bin/pdb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { PdbFile, PeFile } from 'pdb-guid';

export async function tryGetPdbGuid(pdbFilePath: string): Promise<string> {
try {
const pdbFile = await PdbFile.createFromFile(pdbFilePath);
return `${pdbFile.guid}`;
} catch (error) {
console.log(`Could not get guid for ${pdbFilePath}...`);
}

return '';
}

export async function tryGetPeGuid(peFilePath: string): Promise<string> {
try {
const pdbFile = await PeFile.createFromFile(peFilePath);
return `${pdbFile.guid}`;
} catch (error) {
console.log(`Could not get guid for ${peFilePath}...`);
}

return '';
}
23 changes: 23 additions & 0 deletions spec/pdb.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { tryGetPdbGuid, tryGetPeGuid } from '../bin/pdb';

describe('pdb', () => {
describe('tryGetPdbGuid', () => {
it('should return guid for c++ pdb', async () => {
return expectAsync(tryGetPdbGuid('spec/support/bugsplat.pdb')).toBeResolvedTo('E546B55B6D214E86871B40AC35CD0D461');
});

it('should return empty guid for unrecognized pdb', () => {
return expectAsync(tryGetPdbGuid('spec/support/portable.pdb')).toBeResolvedTo('');
});
});

describe('tryGetPeGuid', () => {
it('should return guid for c++ exe', () => {
return expectAsync(tryGetPeGuid('spec/support/bssndrpt.exe')).toBeResolvedTo('64FB82D565000');
});

it('should return empty guid for unrecognized pe file', () => {
return expectAsync(tryGetPeGuid('spec/support/corrupt.exe')).toBeResolvedTo('');
});
});
});
1 change: 1 addition & 0 deletions spec/support/corrupt.exe
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
not an exe!
Binary file added spec/support/portable.pdb
Binary file not shown.

0 comments on commit b93aa61

Please sign in to comment.