Skip to content

Commit 249af15

Browse files
committed
Only allow characters and numbers in attributes
1 parent a167dce commit 249af15

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

compiler/src/dotty/tools/dotc/core/tasty/AttributePickler.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ object AttributePickler:
1818
for attribute <- attributes do
1919
val bytes = attribute.getBytes(StandardCharsets.UTF_8).nn
2020
val length = bytes.length
21+
assert("[a-zA-Z0-9]+".r.matches(attribute), s"Malformed attribute: $attribute\n. Attribute must match [a-zA-Z0-9]+")
2122
buf.writeNat(length)
2223
buf.writeBytes(bytes, length)
2324
end pickleAttributes

compiler/src/dotty/tools/dotc/core/tasty/AttributeUnpickler.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class AttributeUnpickler(reader: TastyReader):
1616
val length = readNat()
1717
val bytes = readBytes(length)
1818
val attribute = new String(bytes, StandardCharsets.UTF_8)
19+
assert("[a-zA-Z0-9]+".r.matches(attribute), s"Malformed attribute: $attribute\n. Attribute must match [a-zA-Z0-9]+")
1920
attributesBuilder += attribute
2021
}
2122
attributesBuilder.result()

tasty/src/dotty/tools/tasty/TastyFormat.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,13 @@ All elements of a position section are serialized as Ints
265265
266266
Standard Section: "Comments" Comment*
267267
```none
268-
Comment = Length Bytes LongInt // Raw comment's bytes encoded as UTF-8, followed by the comment's coordinates.
268+
Comment = UTF8 LongInt // Raw comment's bytes encoded as UTF-8, followed by the comment's coordinates.
269269
```
270270
271-
Standard Section: "Attributes" UTF8*
271+
Standard Section: "Attributes" Attribute*
272+
```none
273+
Attribute = UTF8 // attributes match the regex [a-zA-Z0-9]+
274+
```
272275
273276
**************************************************************************************/
274277

0 commit comments

Comments
 (0)