Skip to content

Commit 6348c70

Browse files
committed
Merge remote-tracking branch 'origin/alejandro.gonzalez/APPSEC-69139-resteasy-bound-multipart' into alejandro.gonzalez/APPSEC-69139-resteasy-bound-multipart
2 parents 8cc1a7e + 0756e62 commit 6348c70

129 files changed

Lines changed: 4367 additions & 1200 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

components/json/src/main/java/datadog/json/JsonWriter.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public final class JsonWriter implements Flushable, AutoCloseable {
1919
private final JsonStructure structure;
2020

2121
private boolean requireComma;
22+
private int bytesWritten;
2223

2324
/** Creates a writer with structure check. */
2425
public JsonWriter() {
@@ -245,6 +246,11 @@ public void flush() {
245246
}
246247
}
247248

249+
/** Approximate number of bytes written so far. */
250+
public int sizeInBytes() {
251+
return this.bytesWritten;
252+
}
253+
248254
@Override
249255
public void close() {
250256
try {
@@ -268,13 +274,15 @@ private void endsValue() {
268274
private void write(char ch) {
269275
try {
270276
this.writer.write(ch);
277+
this.bytesWritten++;
271278
} catch (IOException ignored) {
272279
}
273280
}
274281

275282
private void writeStringLiteral(String str) {
276283
try {
277284
this.writer.write('"');
285+
int count = 1;
278286

279287
for (int i = 0; i < str.length(); ++i) {
280288
char c = str.charAt(i);
@@ -286,33 +294,40 @@ private void writeStringLiteral(String str) {
286294
this.writer.write(HEX_DIGITS[(c >>> 8) & 0xF]);
287295
this.writer.write(HEX_DIGITS[(c >>> 4) & 0xF]);
288296
this.writer.write(HEX_DIGITS[c & 0xF]);
297+
count += 6;
289298
} else {
290299
switch (c) {
291300
case '"': // Quotation mark
292301
case '\\': // Reverse solidus
293302
case '/': // Solidus
294303
this.writer.write('\\');
295304
this.writer.write(c);
305+
count += 2;
296306
break;
297307
case '\b': // Backspace
298308
this.writer.write('\\');
299309
this.writer.write('b');
310+
count += 2;
300311
break;
301312
case '\f': // Form feed
302313
this.writer.write('\\');
303314
this.writer.write('f');
315+
count += 2;
304316
break;
305317
case '\n': // Line feed
306318
this.writer.write('\\');
307319
this.writer.write('n');
320+
count += 2;
308321
break;
309322
case '\r': // Carriage return
310323
this.writer.write('\\');
311324
this.writer.write('r');
325+
count += 2;
312326
break;
313327
case '\t': // Horizontal tab
314328
this.writer.write('\\');
315329
this.writer.write('t');
330+
count += 2;
316331
break;
317332
default:
318333
if (c < 0x20) {
@@ -322,22 +337,28 @@ private void writeStringLiteral(String str) {
322337
this.writer.write('0');
323338
this.writer.write(HEX_DIGITS[(c >>> 4) & 0xF]);
324339
this.writer.write(HEX_DIGITS[c & 0xF]);
340+
count += 6;
325341
} else {
326342
this.writer.write(c);
343+
count += 1;
327344
}
328345
break;
329346
}
330347
}
331348
}
332349

333350
this.writer.write('"');
351+
count += 1;
352+
353+
this.bytesWritten += count;
334354
} catch (IOException ignored) {
335355
}
336356
}
337357

338358
private void writeStringRaw(String str) {
339359
try {
340360
this.writer.write(str);
361+
this.bytesWritten += str.length(); // exact if ASCII, estimate otherwise
341362
} catch (IOException ignored) {
342363
}
343364
}

components/json/src/test/java/datadog/json/JsonWriterTest.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,54 @@ void testCompleteObject() {
165165
}
166166
}
167167

168+
@Test
169+
void testSizeInBytes() {
170+
try (JsonWriter writer = new JsonWriter()) {
171+
assertEquals(0, writer.sizeInBytes(), "Check empty writer size");
172+
173+
writer.beginArray();
174+
assertSizeInBytes(writer, "Check size after plain ASCII string");
175+
writer.value("bar");
176+
177+
assertSizeInBytes(writer, "Check size after escaped characters");
178+
writer.value("\"\\/");
179+
180+
assertSizeInBytes(writer, "Check size after named escapes");
181+
writer.value("\b\f\n\r\t");
182+
183+
assertSizeInBytes(writer, "Check size after control character escape");
184+
writer.value("\u0001");
185+
186+
assertSizeInBytes(writer, "Check size after non-ASCII character escape");
187+
writer.value("café");
188+
189+
assertSizeInBytes(writer, "Check size after int value");
190+
writer.value(3);
191+
192+
assertSizeInBytes(writer, "Check size after long value");
193+
writer.value(3456789123L);
194+
195+
assertSizeInBytes(writer, "Check size after float value");
196+
writer.value(3.142f);
197+
198+
assertSizeInBytes(writer, "Check size after double value");
199+
writer.value(PI);
200+
201+
assertSizeInBytes(writer, "Check size after boolean value");
202+
writer.value(true);
203+
204+
assertSizeInBytes(writer, "Check size after null value");
205+
writer.nullValue();
206+
207+
writer.endArray();
208+
assertSizeInBytes(writer, "Check final size matches written bytes");
209+
}
210+
}
211+
212+
private static void assertSizeInBytes(JsonWriter writer, String message) {
213+
assertEquals(writer.toByteArray().length, writer.sizeInBytes(), message);
214+
}
215+
168216
@Test
169217
void testCompleteArray() {
170218
try (JsonWriter writer = new JsonWriter()) {

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BuildkiteInfo.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class BuildkiteInfo implements CIProviderInfo {
2323
public static final String BUILDKITE = "BUILDKITE";
2424
public static final String BUILDKITE_PROVIDER_NAME = "buildkite";
2525
public static final String BUILDKITE_PIPELINE_ID = "BUILDKITE_BUILD_ID";
26-
public static final String BUILDKITE_PIPELINE_NAME = "BUILDKITE_PIPELINE_SLUG";
26+
public static final String BUILDKITE_PIPELINE_SLUG = "BUILDKITE_PIPELINE_SLUG";
27+
public static final String BUILDKITE_PIPELINE_DISPLAY_NAME = "BUILDKITE_PIPELINE_NAME";
2728
public static final String BUILDKITE_PIPELINE_NUMBER = "BUILDKITE_BUILD_NUMBER";
2829
public static final String BUILDKITE_BUILD_URL = "BUILDKITE_BUILD_URL";
2930
public static final String BUILDKITE_JOB_ID = "BUILDKITE_JOB_ID";
@@ -67,7 +68,8 @@ public CIInfo buildCIInfo() {
6768
return CIInfo.builder(environment)
6869
.ciProviderName(BUILDKITE_PROVIDER_NAME)
6970
.ciPipelineId(environment.get(BUILDKITE_PIPELINE_ID))
70-
.ciPipelineName(environment.get(BUILDKITE_PIPELINE_NAME))
71+
.ciPipelineName(environment.get(BUILDKITE_PIPELINE_SLUG))
72+
.ciPipelineDisplayName(environment.get(BUILDKITE_PIPELINE_DISPLAY_NAME))
7173
.ciPipelineNumber(environment.get(BUILDKITE_PIPELINE_NUMBER))
7274
.ciPipelineUrl(ciPipelineUrl)
7375
.ciJobId(environment.get(BUILDKITE_JOB_ID))

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/CIInfo.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public static final class Builder {
2222
private String ciProviderName;
2323
private String ciPipelineId;
2424
private String ciPipelineName;
25+
private String ciPipelineDisplayName;
2526
private String ciStageName;
2627
private String ciJobId;
2728
private String ciJobName;
@@ -53,6 +54,11 @@ public Builder ciPipelineName(String ciPipelineName) {
5354
return this;
5455
}
5556

57+
public Builder ciPipelineDisplayName(String ciPipelineDisplayName) {
58+
this.ciPipelineDisplayName = ciPipelineDisplayName;
59+
return this;
60+
}
61+
5662
public Builder ciStageName(String ciStageName) {
5763
this.ciStageName = ciStageName;
5864
return this;
@@ -123,6 +129,7 @@ public CIInfo build() {
123129
ciProviderName,
124130
ciPipelineId,
125131
ciPipelineName,
132+
ciPipelineDisplayName,
126133
ciStageName,
127134
ciJobId,
128135
ciJobName,
@@ -140,6 +147,7 @@ public CIInfo build() {
140147
private final String ciProviderName;
141148
private final String ciPipelineId;
142149
private final String ciPipelineName;
150+
private final String ciPipelineDisplayName;
143151
private final String ciStageName;
144152
private final String ciJobId;
145153
private final String ciJobName;
@@ -153,13 +161,14 @@ public CIInfo build() {
153161
private final Map<String, String> additionalTags;
154162

155163
public CIInfo() {
156-
this(null, null, null, null, null, null, null, null, null, null, null, null, null, null);
164+
this(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
157165
}
158166

159167
public CIInfo(
160168
String ciProviderName,
161169
String ciPipelineId,
162170
String ciPipelineName,
171+
String ciPipelineDisplayName,
163172
String ciStageName,
164173
String ciJobId,
165174
String ciJobName,
@@ -174,6 +183,7 @@ public CIInfo(
174183
this.ciProviderName = ciProviderName;
175184
this.ciPipelineId = ciPipelineId;
176185
this.ciPipelineName = ciPipelineName;
186+
this.ciPipelineDisplayName = ciPipelineDisplayName;
177187
this.ciStageName = ciStageName;
178188
this.ciJobId = ciJobId;
179189
this.ciJobName = ciJobName;
@@ -199,6 +209,10 @@ public String getCiPipelineName() {
199209
return ciPipelineName;
200210
}
201211

212+
public String getCiPipelineDisplayName() {
213+
return ciPipelineDisplayName;
214+
}
215+
202216
public String getCiStageName() {
203217
return ciStageName;
204218
}
@@ -267,6 +281,7 @@ public boolean equals(Object o) {
267281
return Objects.equals(ciProviderName, ciInfo.ciProviderName)
268282
&& Objects.equals(ciPipelineId, ciInfo.ciPipelineId)
269283
&& Objects.equals(ciPipelineName, ciInfo.ciPipelineName)
284+
&& Objects.equals(ciPipelineDisplayName, ciInfo.ciPipelineDisplayName)
270285
&& Objects.equals(ciStageName, ciInfo.ciStageName)
271286
&& Objects.equals(ciJobId, ciInfo.ciJobId)
272287
&& Objects.equals(ciJobName, ciInfo.ciJobName)
@@ -286,6 +301,7 @@ public int hashCode() {
286301
hash = 31 * hash + (ciProviderName == null ? 0 : ciProviderName.hashCode());
287302
hash = 31 * hash + (ciPipelineId == null ? 0 : ciPipelineId.hashCode());
288303
hash = 31 * hash + (ciPipelineName == null ? 0 : ciPipelineName.hashCode());
304+
hash = 31 * hash + (ciPipelineDisplayName == null ? 0 : ciPipelineDisplayName.hashCode());
289305
hash = 31 * hash + (ciStageName == null ? 0 : ciStageName.hashCode());
290306
hash = 31 * hash + (ciJobId == null ? 0 : ciJobId.hashCode());
291307
hash = 31 * hash + (ciJobName == null ? 0 : ciJobName.hashCode());
@@ -312,6 +328,9 @@ public String toString() {
312328
+ ", ciPipelineName='"
313329
+ ciPipelineName
314330
+ '\''
331+
+ ", ciPipelineDisplayName='"
332+
+ ciPipelineDisplayName
333+
+ '\''
315334
+ ", ciStageName='"
316335
+ ciStageName
317336
+ '\''

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/CITagsProvider.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public Map<String, String> getCiTags(CIInfo ciInfo, PullRequestInfo pullRequestI
2929
.withCiProviderName(ciInfo.getCiProviderName())
3030
.withCiPipelineId(ciInfo.getCiPipelineId())
3131
.withCiPipelineName(ciInfo.getCiPipelineName())
32+
.withCiPipelineDisplayName(ciInfo.getCiPipelineDisplayName())
3233
.withCiStageName(ciInfo.getCiStageName())
3334
.withCiJobName(ciInfo.getCiJobName())
3435
.withCiJobId(ciInfo.getCiJobId())
@@ -82,6 +83,10 @@ public CITagsBuilder withCiPipelineName(final String ciPipelineName) {
8283
return putTagValue(Tags.CI_PIPELINE_NAME, ciPipelineName);
8384
}
8485

86+
public CITagsBuilder withCiPipelineDisplayName(final String ciPipelineDisplayName) {
87+
return putTagValue(Tags.CI_PIPELINE_DISPLAY_NAME, ciPipelineDisplayName);
88+
}
89+
8590
public CITagsBuilder withCiPipelineNumber(final String ciPipelineNumber) {
8691
return putTagValue(Tags.CI_PIPELINE_NUMBER, ciPipelineNumber);
8792
}

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/codeowners/CodeownersImpl.java

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
import java.io.BufferedReader;
55
import java.io.IOException;
66
import java.io.Reader;
7-
import java.util.ArrayDeque;
87
import java.util.ArrayList;
98
import java.util.Collection;
109
import java.util.Collections;
11-
import java.util.Deque;
1210
import java.util.LinkedHashMap;
1311
import java.util.LinkedHashSet;
1412
import java.util.List;
@@ -20,9 +18,9 @@
2018

2119
public class CodeownersImpl implements Codeowners {
2220

23-
private final Collection<Section> sections;
21+
private final List<Section> sections;
2422

25-
private CodeownersImpl(Collection<Section> sections) {
23+
private CodeownersImpl(List<Section> sections) {
2624
this.sections = sections;
2725
}
2826

@@ -32,17 +30,25 @@ private CodeownersImpl(Collection<Section> sections) {
3230
*/
3331
@Override
3432
public @Nullable Collection<String> getOwners(@Nonnull String path) {
35-
char[] pathCharacters = path.toCharArray();
33+
if (sections.size() == 1) {
34+
Section section = sections.get(0);
35+
if (section.isExcluded(path)) {
36+
return new ArrayList<>();
37+
}
38+
Entry entry = section.findMatchingEntry(path);
39+
return entry != null ? new ArrayList<>(entry.getOwners()) : null;
40+
}
41+
3642
Set<String> owners = null;
3743
for (Section section : sections) {
38-
if (section.isExcluded(pathCharacters)) {
44+
if (section.isExcluded(path)) {
3945
if (owners == null) {
4046
owners = new LinkedHashSet<>();
4147
}
4248
continue;
4349
}
4450

45-
Entry entry = section.findMatchingEntry(pathCharacters);
51+
Entry entry = section.findMatchingEntry(path);
4652
if (entry != null) {
4753
if (owners == null) {
4854
owners = new LinkedHashSet<>();
@@ -90,36 +96,4 @@ public static Codeowners parse(Reader r) throws IOException {
9096
sections.addAll(namedSections.values());
9197
return new CodeownersImpl(sections);
9298
}
93-
94-
private static final class Section {
95-
96-
private final Deque<Entry> entries = new ArrayDeque<>();
97-
private final Collection<Entry> exclusions = new ArrayList<>();
98-
99-
private void add(Entry entry) {
100-
if (entry.isExclusion()) {
101-
exclusions.add(entry);
102-
} else {
103-
entries.offerFirst(entry);
104-
}
105-
}
106-
107-
private boolean isExcluded(char[] path) {
108-
for (Entry exclusion : exclusions) {
109-
if (exclusion.getMatcher().consume(path, 0) >= 0) {
110-
return true;
111-
}
112-
}
113-
return false;
114-
}
115-
116-
private @Nullable Entry findMatchingEntry(char[] path) {
117-
for (Entry entry : entries) {
118-
if (entry.getMatcher().consume(path, 0) >= 0) {
119-
return entry;
120-
}
121-
}
122-
return null;
123-
}
124-
}
12599
}

0 commit comments

Comments
 (0)